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

Native Development

Reply
Developer
Curahee
Posts: 210
Registered: ‎01-12-2013
My Device: z30
My Carrier: Mobile Vikings
Accepted Solution

AES/ECB/PKCS7Padding encryption

Dear developers

 

I am converting an application from Android to native BlackBerry 10. The application uses AES to encrypt data. So I went looking for how to do it in BlackBerry 10 but it seems not that easy. In Java it looks like this:

 

byte[] arrayOfByte1 = HexToByte(key);
byte[] arrayOfByte2 = data.getBytes("UTF8");

 

SecretKeySpec localSecretKeySpec = new SecretKeySpec(arrayOfByte1, "AES");


Cipher localCipher = Cipher.getInstance("AES/ECB/PKCS7Padding");
localCipher.init(1, localSecretKeySpec);


String str = Base64.encodeBytes(localCipher.doFinal(arrayOfByte2));

 

But how can I easily achieve this in BlackBerry 10? I allready tried it with downloading this example:

https://www.dropbox.com/s/czxmuhgzd8ak1zz/AesAlgoSample.zip

 

But how to add the padding to it? This encryption stuff is kinda hard on BB10...

______________________________________________________
beRail: BlackBerry World - GitHub
Mobile Vikings: BlackBerry World - GitHub
Park in Brussels: BlackBerry World
Please use plain text.
Developer
peter9477
Posts: 6,473
Registered: ‎12-08-2010
My Device: PlayBook, Z10
My Carrier: none

Re: AES/ECB/PKCS7Padding encryption

https://twitter.com/robbieDubya of BlackBerry has created a nice AESCryptoDemo for Cascades. I was able to follow through it and extract pieces that I used in a Python app to get AES encryption working. He includes pad/unpad routines. Should be all you need.

https://github.com/blackberry/Cascades-Community-Samples/tree/master/AESCryptoDemo

Peter Hansen -- (BB10 and dev-related blog posts at http://peterhansen.ca.)
Author of White Noise and Battery Guru for BB10 and for PlayBook | Get more from your battery!
Please use plain text.
Developer
Curahee
Posts: 210
Registered: ‎01-12-2013
My Device: z30
My Carrier: Mobile Vikings

Re: AES/ECB/PKCS7Padding encryption

Thank you very much. I think this information will help me to resolve my problem. :smileyhappy:
______________________________________________________
beRail: BlackBerry World - GitHub
Mobile Vikings: BlackBerry World - GitHub
Park in Brussels: BlackBerry World
Please use plain text.