public and private key pair in Java

  • Follow


Hi, I have the following question:
If I encrypted some text with the public key K, and tried to decrypt it
with a wrong key (i.e. a key which is NOT the corresponding private
key), will I get an exception, or is there is a boolean function to
test whether the right key has been used?

0
Reply tmuldner (10) 10/28/2005 8:13:41 PM

solid wrote:
> Hi, I have the following question:
> If I encrypted some text with the public key K, and tried to decrypt it
> with a wrong key (i.e. a key which is NOT the corresponding private
> key), will I get an exception, or is there is a boolean function to
> test whether the right key has been used?

   If the encryption with the public key was done with a proper padding 
method, e.g. OAEP, the decryption will fail if you use the wrong private 
key.

--Mike Amling
0
Reply Mike 10/28/2005 11:41:11 PM


By "fail" what do you mean? Exception?
And, is it using Java cryptography API?

0
Reply solid 10/29/2005 3:53:45 AM

Hi,

There's no boolean function available in the JCE framework to tell if
the given private key is the correct one.
If your 'Cipher' instance was correctly initialised, then it will throw
either an 'IllegalBlockSizeException' or a 'BadPaddingException' during
the call of method 'doFinal()' if the wrong key was given (or if the
given encrypted data is invalid). Please note that 'doFinal' might, in
rare occasions, not throw an exception and return garbled data for
unmatched keys, but it depends on the algorithm and padding used. If
you stumble into this situation you'll probably notice it anyway since
you won't be able to interpret the decrypted information.

Regards,
 Tommy Gr=E4ndefors
 www.pheox.com

solid wrote:
> By "fail" what do you mean? Exception?
> And, is it using Java cryptography API?

0
Reply iso 10/29/2005 7:05:09 PM

solid wrote:
> By "fail" what do you mean? Exception?
> And, is it using Java cryptography API?

   You need to know what padding method you used to encrypt "some text 
with the public key". I don't know if you're using OAEP, or another good 
padding method (e.g. SAEP+), or not. If you used no padding, then you do 
not have secure encryption. If you used a good padding method, and you 
supply an incorrect private key, you may get an Exception or a null 
object, but if you get back some text, it will be your original text.

   The OAEP paper is at http://www-cse.ucsd.edu/users/mihir/papers/oae.pdf.

--Mike Amling
0
Reply Mike 10/31/2005 6:18:34 PM

4 Replies
261 Views

(page loaded in 1.147 seconds)

Similiar Articles:













7/23/2012 7:13:27 PM


Reply: