Forum Stats

  • 3,837,547 Users
  • 2,262,269 Discussions
  • 7,900,317 Comments

Discussions

Decrypting string in AES

Lorenzo Avoledo
Lorenzo Avoledo Member Posts: 13 Blue Ribbon
edited Oct 21, 2014 6:04AM in Cryptography

I have to decrypt in java a string crypted in AES 256 from a c# class.

I know the init vector and the passphrase, both are 32 bytes string.

I made a try with this code:

byte [] iv = "1234567812345678".getBytes("UTF-8");

byte [] keyBytes = "1234567812345678".getBytes("UTF-8");

SecretKey aesKey = new SecretKeySpec(keyBytes, "AES");

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

cipher.init(Cipher.DECRYPT_MODE, aesKey, new IvParameterSpec(iv));

byte[] result = cipher.doFinal(cipherBytes);

But when i put iv and keyBytes of 32 bytes i get this error

Exception in thread "main" java.security.InvalidAlgorithmParameterException: Wrong IV length: must be 16 bytes long

  at com.sun.crypto.provider.SunJCE_h.a(DashoA12275)

  at com.sun.crypto.provider.AESCipher.engineInit(DashoA12275)

  at javax.crypto.Cipher.a(DashoA12275)

  at javax.crypto.Cipher.a(DashoA12275)

  at javax.crypto.Cipher.init(DashoA12275)

  at javax.crypto.Cipher.init(DashoA12275)

Can anyone help me?

Thank you

Lorenzo

Answers

This discussion has been closed.