David R. David R. - 1 month ago 12
Android Question

Android AES encryption secret key

I'm developping an Android app and i wanna do encryption with AES-128.
I use secret key and text with hexadecimal.

I use this website : http://testprotect.com/appendix/AEScalc to compute the AES encryption with the following key : "c4dcc3c6ce0acaec4327b6098260b0be" and my text to encrypt is : "6F4B1B252A5F0C3F2992E1A65E56E5B8" (hexadecimal).

So the result from this website give me "859499d0802de8cc6ba4f208da648a8f" and that's the result i wanna get.

I find some code on the net, but a lot uses seed to generate random secret key and i wanna fix the secret key.
Actually i'm using the following code, i think it's the code i need but the result gives me

D/resultdebug: 72adc67b6d11e1c5fb89ddf5faeb0e030686b91f8bfaf6c41335f08955343f87

and it's not the same result than the website, that i want.

String text16 = "6F4B1B252A5F0C3F2992E1A65E56E5B8";
String secret16 = "c4dcc3c6ce0acaec4327b6098260b0be";

SecretKeySpec sks = new SecretKeySpec(secret16.getBytes(),"AES");
Cipher c = Cipher.getInstance("AES");

c.init(Cipher.ENCRYPT_MODE, sks);
byte[] ciphertext = c.doFinal();
Log.d("resultdebug",new String(Hex.encode(ciphertext), "ASCII"));

Could you please tell me what's wrong, thanks.


You are not converting the hex to binary, you are getting the binary of the characters not the value that is hex encoded.