Reputation: 1
This is my code so far. Every time I run it, I receive a bad padding exception only while trying to decrypt. If I swap the use of my private and public keys it still throws the same exception in decrypt. This makes me believe that it is an issue with the Decrypt itself. Any thoughts on what I am doing wrong?
try {
Cipher Bob_Message_Verify = Cipher.getInstance("RSA");
Bob_Message_Verify.init(Cipher.DECRYPT_MODE, Alice_Pair_I.getPublic());
Bob_Verification_Message_Decrypt = (Bob_Message_Verify.doFinal(Bob_Verification_Message_Encrypt));
}catch(NoSuchAlgorithmException e)
{
throw new OTPException("Not RSA");
}
catch(IllegalBlockSizeException e)
{
throw new OTPException("Wrong Block Size");
}
catch(NoSuchPaddingException e)
{
throw new OTPException("No Padding");
}
catch(InvalidKeyException e)
{
throw new OTPException("Invalid Key");
}
catch(BadPaddingException e)
{
throw new OTPException("Bad Padding");
}
Upvotes: 0
Views: 423
Reputation: 94058
The reason that you are getting an error is that you are trying to verify with a Cipher
. You need to use a Signature
instance of that. Note that the specifics of signature generation are rather different from a cipher. Signature verification conversely is not the same as decryption with the public key.
Upvotes: 1