I have a given encrypted text and I want to decrypt it with given private key file.
I wrote this code
ObjectInputStream inputStream = new ObjectInputStream( new FileInputStream( PRIVATE_KEY_FILE ) ) ;
PrivateKey privateKey = (PrivateKey) inputStream.readObject() ;
Cipher cipher = Cipher.getInstance( "RSA" ) ;
cipher.init( Cipher.DECRYPT_MODE , privateKey ) ;
byte[] decryptedText = cipher.doFinal( dText ) ; //this is line 56
I gets this error whenever I run my code.
Exception in thread "main" javax.crypto.BadPaddingException: Blocktype mismatch: 0
at sun.security.rsa.RSAPadding.unpadV15(RSAPadding.java:328)
at sun.security.rsa.RSAPadding.unpad(RSAPadding.java:272)
at com.sun.crypto.provider.RSACipher.doFinal(RSACipher.java:356)
at com.sun.crypto.provider.RSACipher.engineDoFinal(RSACipher.java:382)
at javax.crypto.Cipher.doFinal(Cipher.java:2087)
at RSADecryption.decrypt(RSADecryption.java:56)
at RSADecryption.main(RSADecryption.java:73)
How can I get rid of this error?