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

New Developer
Posts: 5
Registered: ‎12-05-2009
My Device: Curve 8900


Hi All,


I am developing a BB application that will send user info to my server. So thought of encrypting the user info while sending it to the server.


Am using AES algorithm for encryption and decryption.


On the server side, When the decryption is done, it says key mismatch. Am struck in this for quiet a long time.

Any help in this regard is much appreciated!





Posts: 213
Registered: ‎07-18-2008
My Device: Not Specified

Re: Encryption

theses article show some examples on how to do encryption and might be helpful to you:


Basic Encryption


How to- Use Advanced Encryption



problemSolved() ? kudosPlease():kudosPlease();
New Developer
Posts: 94
Registered: ‎03-06-2009
My Device: Not Specified

Re: Encryption

Below is the code I used for AES encryption/decryption.

In my application, I encrypted the data and then I decrypted it usingopenssl.

	private void dummyCBC() {
		String plainData = "We have done it....";
		String key = "this is my key";
		try {
			byte[] encryptedData = CipherManager.aesCBCEncryption(plainData.getBytes(),0, key);
			System.out.println("CBC encrypted data is  :: "+new String(encryptedData));
		} catch (CryptoException e) {
			System.out.println("CBS CryptoException :: "+e);
		} catch (IOException e) {
			System.out.println("CBS IOException :: "+e);
		} catch (Exception e) {
			System.out.println("CBS Exception :: "+e);

		public static String encrypt(String keyString, String plainText, InitializationVector initVec) {
		String encryptedText = null;
		try {
			byte[] keyData = keyString.getBytes();
			AESKey key = new AESKey(keyData);
			AESEncryptorEngine engine = new AESEncryptorEngine( key );
			PKCS5FormatterEngine formatterEngine = new PKCS5FormatterEngine(new CBCEncryptorEngine(engine,initVec));
			ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
			BlockEncryptor encryptor = new BlockEncryptor(formatterEngine, outputStream);
			byte[] encryptedData = outputStream.toByteArray();
			encryptedText = new String(encryptedData);
		} catch (Exception e) {
			System.out.println("Exception in CBC encryption :: "+e);

		return encryptedText;

	public static String decrypt(String keyString, String encryptedText, InitializationVector initVec) {
		String plainText = null;
		try {
			byte[] keyData = keyString.getBytes();
			AESKey key = new AESKey( keyData);
			AESDecryptorEngine engine = new AESDecryptorEngine( key );
			PKCS5UnformatterEngine unformatterEngine = new PKCS5UnformatterEngine(new CBCDecryptorEngine(engine,initVec));
			ByteArrayInputStream inputStream = new ByteArrayInputStream(encryptedText.getBytes());
			BlockDecryptor decryptor = new BlockDecryptor(unformatterEngine, inputStream);
			byte[] temp = new byte[ 100 ];
			DataBuffer buffer = new DataBuffer();
			for( ;; ) {
				int bytesRead = decryptor.read( temp );
				buffer.write( temp, 0, bytesRead );
				if( bytesRead < 100 ) {
			plainText = new String(buffer.getArray());
		} catch (Exception e) {
			System.out.println("Exception in CBC encryption :: "+e);
		return plainText;




Trusted Contributor
Posts: 227
Registered: ‎12-16-2009
My Device: 9530,8900,9000
My Carrier: Airtel,Docomo

Re: Encryption

Can you post that class CipherManager ???

Lathiya Himanshu
Posts: 19,631
Registered: ‎07-14-2008
My Device: Not Specified

Re: Encryption

My experience is that the implementations will be compatible (AFAIK they both have to pass certain standard tests giving the correct results), however you will need to make 100% sure that you implement in exactly the same way.  So make sure you can "roundtrip" the same data on both platforms, with the same bytes in each of the intermediary steps.  If you see different results, look for variations in the implementation before you assume the encryption is different - it isn't.