Open tfzxyinhao opened 2 years ago
Your key length is not 32 bytes.
len(12345678901234567890123456789012) = 32
len(12345678901234567890123456789012) = 32
This is not a key. The key should be a slice of 32 bytes, not a string of 32 characters.
The correctness is already tested with these testcases:
AES is a symmetric cipher algorithm, which means that the cipher text's length should be identical with the text. Your Java output:
James
u9QmnI+gjMUK9LETbm2eWA==
should have included some kind of padding, because it is exactly 16bytes length (128-bits), which is AES's block length.
A little bit of searching shows that:
For Oracle JDK 7 (tested), the default cipher for AES is AES/ECB/PKCS5Padding. The Java Security documentation doesn't mention about this though (http://docs.oracle.com/javase/6/docs/technotes/guides/security/StandardNames.html#algspec), have to do some JUnit testing to find out.
java code
java code ouput
rust code
rust code ouput
base64("12345678901234567890123456789012") = "MTIzNDU2Nzg5MDEyMzQ1Njc4OTAxMjM0NTY3ODkwMTI"
aes online result
Is there anything wrong with how I use it?