我有一个给定的加密文本,我想用给定的私钥文件解密它。
我写了这段代码
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
每当我运行我的代码时,我都会收到此错误。
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)
我怎样才能摆脱这个错误?谢谢...