> i am getting this error
> javax.crypto.BadPaddingException: Given final block
> not properly padded
>
> i am trying to decrypt a cipher txt using a sec. key
> and store the message in a buffer.any solution?
Given the vast amount of detail given above about the problem, I'd have to say:
Better make sure the final block gets properly padded.
> got it!!!
> byte[ ] storing decrypted message should exclude
> padded bits
Since the BadPaddingException is thrown when you are decrypting, I don't see how this can apply. If you are using PKCS5Padding (as is implied by the the exception) then when you decrypt the padding bytes will automatically be removed. No need for you to take any action.
Why not post some code so that we can understand what you are doing. Make sure you use the [code] tags.
byte[] decrypt (byte[] cipher, SecretKeySpec key) throws Exception
{
Cipher aesCipher;
aesCipher = Cipher.getInstance("AES");
System.out.println("check");
aesCipher.init(Cipher.DECRYPT_MODE, key);
// byte[] original=new byte[1024];
byte[] original = aesCipher.doFinal(cipher);
System.out.println("text"+ original);
return original;
}
Since the BadPaddingException is thrown when you are decrypting, I don't see how this can apply. If you are using PKCS5Padding (as is implied by the the exception) then when you decrypt the padding bytes will automatically be removed. No need for you to take any action.
i have used PKCS5Padding....so the original ( above code) is the plain text with padding removed right?
and i get a new exception "IllegalBlockSizeException: Input length must be multiple of 16 when decrypting with padded cipher"
Message was edited by:
sindy