tasos-py / AES-Encryption-Classes

AES encryption in Python, PHP, C#, Java, C++, F#, Ruby, Scala, Node.js
MIT License
145 stars 58 forks source link

Problem with encrypt/decrypt #7

Closed ghost closed 1 year ago

ghost commented 2 years ago

Hi Tasos, when I use your example in c# and php I receive an error massage in php: error:0606508A:digital envelope routines:EVP_DecryptFinal_ex:data not multiple of block length

c# code is: string data = "my data"; string passphrase = "my super strong password"; AesEncryption aes = new AesEncryption("cfb"); byte[] enc = aes.Encrypt(data, passphrase); Debug.WriteLine(Encoding.ASCII.GetString(enc)); //1cFI7AVmg/M7Z84ALEKVC2ZEOfof5qHP5CrIqYF3+1j7OOzDcM8BPjh1IZeVj4wyKDryRKwpIxmfzKI7xXixC2ZYmnl+JP4=

php code is: $data = "1cFI7AVmg/M7Z84ALEKVC2ZEOfof5qHP5CrIqYF3+1j7OOzDcM8BPjh1IZeVj4wyKDryRKwpIxmfzKI7xXixC2ZYmnl+JP4="; $password = "my super strong password"; $aes = new AesEncryption(); $dec = $aes->decrypt($data, $password); echo $dec; //error:0606508A:digital envelope routines:EVP_DecryptFinal_ex:data not multiple of block length

Do you have any idea? Regards Horst

tasos-py commented 2 years ago

Sorry for the late reply, I just noticed this issue. In your code above you're using different modes - CFB in C# and CBC in PHP (CBC is the default). You should be able to get correct results if you use the same mode