03-07-2010 01:01 PM
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 v126.96.36.199a
and on 9700(OS 5.0) - Cryptographic Kernel is v188.8.131.52
03-08-2010 09:49 AM - edited 03-08-2010 09:50 AM
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...
03-08-2010 02:14 PM
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.....
03-08-2010 02:31 PM - edited 03-08-2010 02:32 PM
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).
03-09-2010 06:53 AM
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.