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
Contributor
Posts: 15
Registered: ‎02-28-2010
My Device: Bold 9000
My Carrier: Orange

Crypto API

Hi All,

 

I'm migrating to OS 5.0 and found a problem in my Encryption module.

 

I'm using this code to encrypt text:

 

public ECCryptoSystem ECC_ENG = new ECCryptoSystem(ECCryptoSystem.EC384R1);
ECPublicKey remotePublicKey = new ECPublicKey(ECC_ENG, pubKey);
NoCopyByteArrayOutputStream o = new NoCopyByteArrayOutputStream();
ECIESEncryptor ec_ies_encryptor = new ECIESEncryptor(o, remotePublicKey);

ec_ies_encryptor.write(plainText, 0, plainText.length);
ec_ies_encryptor.close();
			

byte[] ret = o.toByteArray();
return ret;

 

 

Encrypted text is sent to PC application that uses Crypto++ for decryption.

 

When i run this code on OS 4.6, the data decrypted correctly on PC, but when the same code is running under OS 5.0, on PC side i'm getting garbage after decryption.

 

I have no idea what it should be. The only thing i know that on

my Bold 9000(OS 4.6) -  Cryptographic Kernel is v3.8.5.50a 

and on 9700(OS 5.0) - Cryptographic Kernel is v3.8.5.85 

Developer
Posts: 1,474
Registered: ‎04-14-2009
My Device: Not Specified

Re: Crypto API

[ Edited ]

Are there any exceptions thrown?

 

P.S. I'm 99% sure it won't help, but try replacing the NoCopyByteArrayOutputStream with a ByteArrayOutputStream.

 

P.P.S. It's a good idea to print out the public key just before encrption and verify that it's the same on pre-5.0 and v5.0+ handhelds...

Contributor
Posts: 15
Registered: ‎02-28-2010
My Device: Bold 9000
My Carrier: Orange

Re: Crypto API

Hi klyubin,

 

ByteArrayOutputStream not helped.

 

There is no exceptions( original code was with try/catch )

The public key is the same on both platforms, checked it million times.

 

Unfortunately, i can't  compare encrypted text, because it is all the time different, although the public key is the same(not surprise of course)

 

I have no idea..... Smiley Sad

 

 

Developer
Posts: 1,474
Registered: ‎04-14-2009
My Device: Not Specified

Re: Crypto API

[ Edited ]

Suggestions:

 

1. Compare the public key  used in v4.6 and v5.0 by checking the output of ECPublicKey.getECCryptoSystem, getAlgorithm, and getPublicKeyData(boolean) methods.

 

2. Compare the CryptoSystem used in v4.6 and v5.0 by checking the output of various relevant methods in ECCryptoSystem class.

 

3. Compare the ECIES algorithm used in v4.6 and v5.0 by checking the output of ECIESEncryptor.getAlgorithm method.

 

4. Compare the length of the output in v4.6 and v5.0.

 

5. Try playing with the cofactor parameter to the ECIESEncryptor constructor (may be the default has changed, which would be a bug).

Highlighted
Contributor
Posts: 15
Registered: ‎02-28-2010
My Device: Bold 9000
My Carrier: Orange

Re: Crypto API

Thanks for suggestions,

 

Tried all of them, all parameters are the same on 4.6 and 5.0.

 

I did another test: Encrypt text on PC and sent it to BB(5.0) and what a surprise decryption works very well on BB.

 

More than that i tried to encrypt on 5.0 and decrypt on 4.6 and it worked very well too.

 

The problem is not only on PC, i have the same behavior on Nokia and iPhone too.

 

So maybe the problem with public key that created on PC/Nokia side and used for encryption in BB 5.0.

 

I wanted to do another test: create private/public keys on BB and use it on PC side.

 

But unfortunately, i don't know how to construct private/public using BB keys.