Pages

Wednesday, 30 December 2015

[SOLVED] org.bouncycastle.jcajce.provider.symmetric.util.BaseBlockCipher$1: Key length not 128/192/256 bits.

SOURCE
 ----- 
Security.addProvider(new org.bouncycastle.jce.provider.BouncyCastleProvider());
 byte[] input = "Hello".getBytes();
 byte[] keyByte = "1234567812345678123456781234567".getBytes();
 SecretKeySpec key = new SecretKeySpec(keyByte, "AES");
----
ERROR
Dec 31, 2015 11:57:52 AM aes256.AES256 main
SEVERE: null
org.bouncycastle.jcajce.provider.symmetric.util.BaseBlockCipher$1: Key length not 128/192/256 bits.
at org.bouncycastle.jcajce.provider.symmetric.util.BaseBlockCipher.engineInit(Unknown Source)
at org.bouncycastle.jcajce.provider.symmetric.util.BaseBlockCipher.engineInit(Unknown Source)
at javax.crypto.Cipher.init(Cipher.java:1246)
at javax.crypto.Cipher.init(Cipher.java:1186)
at aes256.AES256.main(AES256.java:36)
Caused by: java.lang.IllegalArgumentException: Key length not 128/192/256 bits.
at org.bouncycastle.crypto.engines.AESFastEngine.generateWorkingKey(Unknown Source)
at org.bouncycastle.crypto.engines.AESFastEngine.init(Unknown Source)
at org.bouncycastle.crypto.paddings.PaddedBufferedBlockCipher.init(Unknown Source)
at org.bouncycastle.jcajce.provider.symmetric.util.BaseBlockCipher$BufferedGenericBlockCipher.init(Unknown Source)
... 5 more
BUILD SUCCESSFUL (total time: 1 second)
SOLUTION
Key Leng AES must 128 / 192 / 256 bit or 16 / 24 / 32 Character 
 Security.addProvider(new org.bouncycastle.jce.provider.BouncyCastleProvider());
 byte[] input = "Hello".getBytes();
 byte[] keyByte = "12345678123456781234567812345678".getBytes();
 SecretKeySpec key = new SecretKeySpec(keyByte, "AES");



0 comments:

Post a Comment