Android : Getting wrong Encryption values

on Sunday, September 28, 2014


I am using the following code to encrypt data. To start, I have tried encrypting a message of 0s with a key of 0s and IV of 0s. Still I get a different result than on other platforms including the web tool that is found at http://aes.online-domain-tools.com/ My code is simply this one:



public static byte[] encrypt1(SecretKey secret, byte[] buffer, SecureRandom secRand) throws GeneralSecurityException
{
/* Encrypt the message. */

Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5Padding");


byte[] ivData = new byte[cipher.getBlockSize()];

cipher.init(Cipher.ENCRYPT_MODE, new SecretKeySpec("0000000000000000".getBytes(), "AES"), new IvParameterSpec(ivData));

byte[] ciphertext = cipher.doFinal(buffer);

return Arrays.concatenate(ivData, ciphertext);
}


The hex buffer I get is: F9 5C 7F 6B 19 2B 22 BF FE FD 1B 77 99 33 FB FC


while it should be 66 e9 4b d4 ef 8a 2c 3b 88 4c fa 59 ca 34 2b 2e


0 comments:

Post a Comment