我的RSA解密这部分代码:BadPaddingException:执行会话密钥的RSA加密时,数据必须以零
// Turn the encoded key into a real RSA private key.
// Private keys are encoded in PKCS#8.
PKCS8EncodedKeySpec keySpec = new PKCS8EncodedKeySpec(keyBytes);
KeyFactory keyFactory = KeyFactory.getInstance("RSA");
PrivateKey privateKey = keyFactory.generatePrivate(keySpec);
// Create a cipher using that key to initialize it
Cipher rsaCipher = Cipher.getInstance("RSA/ECB/PKCS1Padding");
// Read in the encrypted bytes of the session key
DataInputStream dis = new DataInputStream(new FileInputStream(fileInput));
byte[] encryptedKeyBytes = new byte[dis.readInt()];
dis.readFully(encryptedKeyBytes);
// Decrypt the session key bytes.
rsaCipher.init(Cipher.DECRYPT_MODE, privateKey);
byte[] rijndaelKeyBytes = rsaCipher.doFinal(encryptedKeyBytes);
// Transform the key bytes into an actual key.
SecretKey rijndaelKey = new SecretKeySpec(rijndaelKeyBytes, "Rijndael");
当我选择私钥文件出现错误,我通过会话进行加密键做的主要文件的非对称加密:
javax.crypto.BadPaddingException:数据必须以零
H启动我能解决这个错误吗?
请在发布之前使用拼写检查器并重新阅读您的问题。确保使用使用良好的标签。 [标签:密码]很难使用,请使用[标签:加密]或[标签:加密]代替 - 如果你不知道你的问题可能不会被注意到。 –