Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Java Development

Reply
Developer
swap_chau
Posts: 179
Registered: ‎06-15-2011
My Device: Storm 9550
My Carrier: Vodaphone
Accepted Solution

Using plain AES

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.

Please use plain text.
Developer
peter_strange
Posts: 19,601
Registered: ‎07-14-2008
My Device: Not Specified

Re: Using plain AES

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?

Please use plain text.
Developer
swap_chau
Posts: 179
Registered: ‎06-15-2011
My Device: Storm 9550
My Carrier: Vodaphone

Re: Using plain AES

[ Edited ]

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.

Please use plain text.
Developer
peter_strange
Posts: 19,601
Registered: ‎07-14-2008
My Device: Not Specified

Re: Using plain AES

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. 

Please use plain text.
Developer
swap_chau
Posts: 179
Registered: ‎06-15-2011
My Device: Storm 9550
My Carrier: Vodaphone

Re: Using plain AES

Yes that worked. Thanks a lot.
Please use plain text.