By "fail" what do you mean? Exception?
And, is it using Java cryptography API?
Tommy Grändefors - 29 Oct 2005 20:05 GMT
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ändefors
www.pheox.com
> By "fail" what do you mean? Exception?
> And, is it using Java cryptography API?
Mike Amling - 31 Oct 2005 19:18 GMT
> 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