11-21-2012 07:08 AM
Hi All,
I have to use AESEncryptorEngine.encrypt() to encrypt data using AES algo. But the whenever I try that, BB throws IllegalArgumentException. There is no detailed message in the exception nor the stacktrace.
I have seen examples where CBCEncryptorEngine &/or PKCS5FormatterEngine being used along with AESEncryptorEngine. This works fine, but I need to use only AES and no padding.
What is the wrokaround for this?
Can you suggest me some Third party encryption library. I tried J2Me version of Bouncy Castle, it is not getting compiled in BB.
Thanks.
Solved! Go to Solution.
11-21-2012 08:11 AM
Can you share the code so we see what you are actually providing the method?
have you tried any sample code and compared with your code?
11-21-2012 08:57 AM - edited 11-21-2012 08:58 AM
Thanks for reply.
Please find my code below:
private void a() {
byte[] key1 = {(byte) 0xA9, (byte) 0x9B, (byte) 0xC8, (byte) 0x32, (byte) 0x56, (byte) 0x35, (byte) 0xE3, (byte) 0x03,
(byte) 0xA9, (byte) 0x9B, (byte) 0xC8, (byte) 0x32, (byte) 0x56, (byte) 0x35, (byte) 0xE3, (byte) 0x03};
AESKey aesKey = new AESKey(key1);//new AESKey(256);
try {
AESEncryptorEngine aesEngine = new AESEncryptorEngine(aesKey);
byte[] output = new byte[5];
byte[] input = "Hello".getBytes();
aesEngine.encrypt(input, 0, output, 0);
String string = new String(output);
LabelField lblField = new LabelField(string);
add(lblField);
} catch (CryptoTokenException e) {
e.printStackTrace();
} catch (CryptoUnsupportedOperationException e) {
e.printStackTrace();
}
}
Whichever codes I looked for, had padding in it, and they work fine, but I need code without padding.
11-21-2012 09:03 AM
I think the problem here is the plainText and cipherText have to match the block length for the algorithm. So make these both 16 bytes and give this another try.
11-21-2012 09:12 AM