Когда я запускаю этот код:
public static byte[] unwrap(PrivateKey privateKey, byte[] wrappedKey) throws Exception {
Cipher cipher = Cipher.getInstance("RSA/ECB/OAEPWithSHA-256AndMGF1Padding");
cipher.init(Cipher.UNWRAP_MODE, privateKey);
return cipher.doFinal(wrappedKey);
}
Строка оператора return выдает следующее:
Exception in thread "main" java.lang.IllegalStateException: Cipher not initialized for encryption/decryption
at javax.crypto.Cipher.checkCipherState(Cipher.java:1754)
at javax.crypto.Cipher.doFinal(Cipher.java:2157)
at x.y.z.decrypt.Main.unwrap(Main.java:47)
at x.y.z.decrypt.Main.main(Main.java:33)
Если я использую DECRYPT_MODE, кажется, что он пытается расшифровать, но я послеразворачивать.Есть предложения?