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
New Developer
ricos
Posts: 48
Registered: ‎06-08-2009
My Device: Bold 9000
Accepted Solution

Problem with ECIESDecryptor...

[ Edited ]

Hi, gurus! 

 

I have an exception when object of ECIESDecryptor created. 

I execute the application on simulator. 

 

The following is a part of my code. 

 

 

... private void eccTest() { ECCryptoSystem _ecc = new ECCryptoSystem(ECCryptoSystem.EC256R1); RichTextField _content; try { ECKeyPair _keyPair = _ecc.createECKeyPair(); ECPublicKey _pubKey = _keyPair.getECPublicKey(); ECPrivateKey _privKey = _keyPair.getECPrivateKey(); /** Encrypt **/ ByteArrayOutputStream _out = new ByteArrayOutputStream(); byte[] plainData = plainText.getBytes(); ECIESEncryptor _encryptor = new ECIESEncryptor(_out, _pubKey); _encryptor.write(plainData); int len = _out.size(); byte[] cryptedText = new byte[len]; System.arraycopy(_out.toByteArray(), 0, cryptedText, 0, len); /** Decrypt **/ ByteArrayInputStream _in = new ByteArrayInputStream(cryptedText, 0, cryptedText.length); ECIESDecryptor decryptor = new ECIESDecryptor(_in, _privKey); // <--- Generate java.lang.IllegalArgumentException byte[] decryptedText = new byte[len]; len = decryptor.read(decryptedText, 0, decryptedText.length); _content = new RichTextField("END."); _appScreen.add(_content); } catch (Exception e) { _content = new RichTextField("Error: " + e.getMessage()); _appScreen.add(_content); } } ...

 


 

 

please help me.

 

Regards, 

 

Ricos

Message Edited by ricos on 06-11-2009 06:09 PM
Message Edited by ricos on 06-11-2009 06:26 PM
Developer
Posts: 5,339
Registered: ‎09-20-2008
My Device: ***
My Carrier: ***

Re: Problem with ECIESDecryptor...

Check these articles:

 

Basic Encryption

 

Advanced Encryption

 

Also check this page:

 

http://na.blackberry.com/eng/developers/resources/developer_labs.jsp#tab_tab_jde

 

Scroll it down and find the section: "Secure BlackBerry Applications"

 

There are two samples to download.

 

I think it is enough to investigate your issue and find the solution.

 

And please do not send me PM with your code.

 

I have no time to dig into the someone's code.

 

Hope you understand.

 

 

Developer
peter_strange
Posts: 19,610
Registered: ‎07-14-2008
My Device: Not Specified

Re: Problem with ECIESDecryptor...

I see I wasn't the only one to get a PM.  Personally I don't mind getting a PM, but I will only respond to posts in this forum.  So just send me a link to the post.  If I have time I will look.

 

Anyway with this, it is clear that there is something wrong with one of the parameters of your constructor. 

 

ECIESDecryptor decryptor = new ECIESDecryptor(_in, _privKey);

 

The _privkey looks OK, so I would check the _in, i.e. the input bytes.  Most specifically, I would check the length and the contents of cryptedText.  If I had to guess, I would suspect this is not what you expect it to be or is not a correct length.  So dump it out, in hex, and see what you have actually got.  Try to decrypt this in some other platform.

 

I am very suspicious of these lines:

 

int len = _out.size(); 

byte[] cryptedText = new byte[len];
System.arraycopy(_out.toByteArray(), 0, cryptedText, 0, len);

 

I would replace these lines with:

 

byte[] cryptedText = out.toByteArray();

 

See how that works.

New Developer
ricos
Posts: 48
Registered: ‎06-08-2009
My Device: Bold 9000

Re: Problem with ECIESDecryptor...

Hi, tbilisoft!

 

I resolved the problem. 

Thanks for your help. 

 

Regards,

 

ricos.
New Developer
ricos
Posts: 48
Registered: ‎06-08-2009
My Device: Bold 9000

Re: Problem with ECIESDecryptor...

Hi, peter_strange!

 

Thanks for your help and time. 

 

Regards, 

ricos. 

 

 

Developer
peter_strange
Posts: 19,610
Registered: ‎07-14-2008
My Device: Not Specified

Re: Problem with ECIESDecryptor...

Can you please mark the Thread as solved?  It would also be useful to indicate what the solution was.  Cheers
New Developer
jcjones
Posts: 5
Registered: ‎08-21-2009
My Device: Not Specified

Re: Problem with ECIESDecryptor...

I'm running into the same issue as the original poster while changing out a bunch of legacy RSA code to using ECIES. I've taken the OP's posted code and replicated his exact problem, the IllegalArgumentException, and am fairly confident that the ciphertext looks right.

 

For example, "moo".getBytes() encrypted produces a 49-length array:


0210D77A4A99E0D968106EBE67E5E12BFDB4CD68F769825E3AC31E7A80CE64F81C2AE00BE904619F5B7EE57B22187022D6

 

which then, once wrapped into a ByteArrayInputStream throws IllegalArgumentException.

 

I promise when I find the solution to this to post what I did. :smileyhappy:

New Developer
jcjones
Posts: 5
Registered: ‎08-21-2009
My Device: Not Specified

Re: Problem with ECIESDecryptor...

I haven't yet found a solution to this, but my workaround was to not use ECIES and do everything manually.

 

For what that's worth.