Page 4 of 6
Posted: Wed Apr 16, 2008 10:21 pm
by agent
Hi there.
First, big thanks to JCV for the great libs.
It would be very nice to have a example for the AES. I need to crypt strings. An example is missing ... :roll:
Can someone code one?
Posted: Thu Apr 17, 2008 11:00 pm
by SFSxOI
I would like to see an example of string encryption in memory myself, using AES (dont know if thats possible). I don't understand the AES stuff at all. Anyone got any examples of string encryption in memory with AES, or any examples of string encryption in memory with these libraries (if its even possible)?
Posted: Sun Apr 20, 2008 1:27 pm
by Inf0Byt3
I don't know if it helps, but I managed to wrap an AES lib in PureBasic. You can find the example inside. The main advantage is that the source is open so it can be tweaked for your needs.
Here's the code
File:1->
AES.zip
The thing is that it may contain bugs,etc. but in my test it worked pretty well

.
Posted: Sun Apr 20, 2008 8:01 pm
by SFSxOI
Thanks Inf0Byt3;
I'll give it a try and play around with it some to see what I can come up with.
Posted: Sun Apr 20, 2008 10:57 pm
by Rook Zimbabwe
And yet, I have used all of those in the military and a couple more...
I knew this was a dicktatorship when the d*c* got re elected!
You watch the Republican Party rig this election as well!
Note to all NIA fugnutz... I didn't download any of the files!
Posted: Mon Apr 21, 2008 12:15 am
by Inf0Byt3
Note to all NIA fugnutz... I didn't download any of the files!
??
Posted: Mon Apr 21, 2008 1:58 am
by Rook Zimbabwe
N @tion al Inte l ligence A gen cy (had to break that up of Cy p h3r would have scanned it)
Posted: Tue Apr 22, 2008 11:42 am
by agent
Hi Inf0Byt3.
Thanks for you lib.
Works fine for me.
But I have one question left:
In your example, you decrypt a string you crypted before. To decrypt, you need the "neededlength" witch was calculated befor crypting the string.
If you just want (or later want) to decrypt a AES-crypted string, you didnt crypt, you dont know the "neededlength". How can I solve this? Or does calculating-routine work for decrypting too? How can I get this value without knowing it from crypting before?
Posted: Tue Apr 22, 2008 11:57 am
by agent
Maybe it is easier to understand if I copy the code:
In your AES.pbi you show an example using
Code: Select all
AESDecrypt(@out,@dec,neededlength,"testpasasdfsdfasfasdfasdfs",#PureAES_CypherMode_256)
My question is:
How can I know the "neededlength" if I did not crypt the text?
Posted: Tue Apr 22, 2008 12:12 pm
by Inf0Byt3
Hi,
I think you'll have to store the length too so you can later decrypt the data. I don't know if there's a way to bypass this.
Posted: Tue Apr 22, 2008 12:22 pm
by agent
Hm....
But if you have a AES256 crypted file. Generated by anyone. How will you decrypt it without knowing the length?
For my work I can solve this by saving the length for any crypted string or setting the length to a virtual value like 1024 (the max lenght I would crypt

) This works fine too, but it is not very professional.
Posted: Tue Apr 22, 2008 2:51 pm
by Inf0Byt3
I understand what you're saying, but almost all the programs that crypt files must have a structure inside. If you want to decrypt a file created by another program it's better that you find the way the file was encrypted, it's header. One developer could use for example:
Signature: 4 bytes
Data: n bytes
Data length: 4 bytes (a long)
Then to read it, you go to Lof()-4 , read the data length, go to offset 4 , read n bytes then decrypt. This varies in function to what the developer chose to encrypt and how. I don't know if there's a "magic" method to decrypt files just by opening them. The length must be stored somewhere inside.
Posted: Sun Aug 31, 2008 8:15 pm
by Fluid Byte
First let me say thank you very much for this. I had to search quite a while to find something wich can encrypt memory of any size while giving the option to set a Key/Password for decryption. I first looked at DES but the input can only be 8 chars long so AES is the way to go for me.
My question is about the memory alignment procedure:
Code: Select all
Procedure Calculate_AES_Padding(*Buffer,Length)
;! http://www.purebasic.fr/english/viewtopic.php?p=66818#66818 !
bytes_remaining.l = Length % 16
padding.l = 16 - bytes_remaining
length_required.l = Length + padding
ProcedureReturn length_required
EndProcedure
Why is it 16? I was asuming the input would be quad alinged so it should be 8, shouldn't it?
As a side note, if you change 16 to the size of quad the length will be the same.
Posted: Sun Aug 31, 2008 8:22 pm
by Inf0Byt3
Hi,
That's not my procudure there but I think I know why 16 was used:
AES has a fixed block size of 128 bits and a key size of 128, 192, or 256 bits...
Since in computing 1 byte equals 8 bits, the fixed block size of 128 bits is normally 128 / 8 = 16 bytes. AES operates on a 4×4 array of bytes, termed the state (versions of Rijndael with a larger block size have additional columns in the state). Most AES calculations are done in a special finite field.
AES uses blocks of 16 bytes. That function calculates how many bytes are needed to make a full 16 byte block so the data will be encrypted without errors. There are many methods of padding, one of them with zero, one with spaces, etc.
Posted: Sun Aug 31, 2008 8:25 pm
by Fluid Byte
Ah ok, thanks for the info.
