您好,我正在嘗試解密用RSA公鑰加密的文件。我有一個對應於pubkey的3072位RSA私鑰。該文件包含密鑰的PKCS8編碼的原始字節。我有一個字節數組rsa_priv。如何從字節數組創建RSAPrivateKey實例?
public void decrypt()
{
try
{
SecretKeySpec sk=new SecretKeySpec(rsa_priv,"RSA/EBC/PKCS8");
Cipher dec = Cipher.getInstance("RSA");
dec.init(Cipher.DECRYPT_MODE, sk,new IvParameterSpec(iv));
//OAEPWithSHA-512AndMGF1Padding
byte temp[];
temp=dec.doFinal(sess);
String t=temp.toString();
System.out.println("Session key is:"+ t);
//session=dec(sess,rsa_priv);OAEPWithSHA-256AndMGF1Padding
}
catch (Exception e)
{
System.out.println("Exception occured:"+ e);
}
}
當我運行這段代碼,我得到以下
Exception occured:java.security.InvalidKeyException: No installed provider
supports this key: javax.crypto.spec.SecretKeySpec
我已經導入這些
import java.io.*;
import javax.crypto.*;
import javax.crypto.spec.IvParameterSpec;
import javax.crypto.spec.SecretKeySpec;
import javax.crypto.KeyGenerator;
import java.security.*;
import javax.crypto.SecretKey;
import javax.crypto.spec.OAEPParameterSpec;
有人請幫我
歡迎新用戶!不要忘記查看Jeremy D所做的更改。請跟進您的問題,並且不要忘記接受解決您問題的答案之一。 –