Marcin Wisniowski - 2008-05-13 16:57:44 - In reply to message 1 from Fernando Martins
Yes, a single AES encoding cycle is limited to max 16 chars (it comes from specyfication). If You like to encode more then 16 chars please look at my new added class in this package: AESCipher.class.php. It uses AES.class.php to encode strings >16 chars.
Fernando Martins - 2008-05-15 21:34:40 - In reply to message 2 from Marcin Wisniowski
Thank you very much for your hawser, it worked just fine.
Now I have another problem. I have to crypt and decrypt messages to and from a Java application and I'm being successful and I think I'm doing something wrong.
I have the following 128 bit key, the bytes are on hex:
24 94 D1 ED 5D 16 CD F7 C2 04 B8 59 A7 59 FE A1
and I'm trying to decrypt the following text ($cryptext in the example bellow):
that corresponds to my message, the following text lines from a file:
#Sun May 04 23:41:11 GMT 2008
#blá blá blá
Here's what I'm doing:
$Cipher = new AESCipher(AES::AES256);
$key_128bit = '2494D1ED5D16CDF7C204B859A759FEA1';
$result = $Cipher->decrypt($cryptext, $key_128bit);
Both $cryptext and $result are different from what I was expecting (as explained above).
Marcin Wisniowski - 2008-05-16 19:52:50 - In reply to message 3 from Fernando Martins
AESCipher Class generates Key from password (text) as in example (test3.php) if You like to use your generated hex key You must edit AESCipherprivate::_generateKey() method
just pass through e key to return. This patch should help :)
Daniel Williams - 2011-02-04 20:59:32 - In reply to message 5 from Fernando Martins
In order to make this work for characters more than 16 do the following:
$cipher = new AESCipher(AES::AES256);
$key = "SET YOUR KEY";
// to encrypt
$encrypted = base64_encode($cipher->encrypt($plaintext, $key));
// to decrypt
echo $cipher->decrypt(base64_decode($encrypted), $key);
the reason you must use base64_encode is that without it the return is binary data that you would have to store into a BLOB entity in mysql. However, if you base64 encode it you can store it in a regular varchar or text field.
You just have to base64_decode it to decrypt it. If you store the encryption in a varchar field without base64_encode you will not be able to decrypt it.