06-11-2009 09:07 PM - edited 06-11-2009 09:26 PM
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
Solved! Go to Solution.
06-13-2009 03:27 AM
Check these articles:
Also check this page:
http://na.blackberry.com/eng/developers/resources/
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.
06-13-2009 09:09 AM
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.
06-14-2009 09:12 PM
Hi, tbilisoft!
I resolved the problem.
Thanks for your help.
Regards,
ricos.
06-14-2009 09:13 PM
Hi, peter_strange!
Thanks for your help and time.
Regards,
ricos.
06-15-2009 04:46 AM
11-16-2009 07:30 PM
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:
0210D77A4A99E0D968106EBE67E5E12BFDB4CD68F769825E3A
which then, once wrapped into a ByteArrayInputStream throws IllegalArgumentException.
I promise when I find the solution to this to post what I did. ![]()
12-01-2009 06:26 PM
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.