我正在尝试解密我的值,它给我java.security.KeyException:错误的数据。异常见代码和堆栈跟踪
代码:
public String Decrypt(String text, String pubkey,PrivateKey privatekey ) {
KeyStore keyStoreBrowser = null;
String decryptedString;
Cipher cipher = null;
byte[] encryptText= new byte[256];
try {
keyStoreBrowser = KeyStore.getInstance("Windows-MY");//, "SunMSCAPI");
keyStore.load(null, null);
String msg=null;
if (keyStoreBrowser != null) {
if (privatekey != null) {
if (text != null) {
encryptText = this.bASE64Decoder.decodeBuffer(text);
cipher = Cipher.getInstance("RSA/ECB/PKCS1Padding",keyStoreBrowser.getProvider());
cipher.init(Cipher.DECRYPT_MODE, privatekey);
decryptedString = new String(cipher.doFinal(encryptText));
}
}
}
} catch (Exception e) {
e.printStackTrace();
System.out.println( e.getMessage());
}
return decryptedString;
}
stacktrace
java.security.ProviderException: java.security.KeyException: Bad Data.
at sun.security.mscapi.RSACipher.doFinal(RSACipher.java:310)
at sun.security.mscapi.RSACipher.engineDoFinal(RSACipher.java:334)
at javax.crypto.Cipher.doFinal(Cipher.java:2165)
at SecApplet.Decrypt(SecApplet.java:1071)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at sun.plugin.javascript.Trampoline.invoke(Unknown Source)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at sun.plugin.javascript.JSClassLoader.invoke(Unknown Source)
at sun.plugin2.liveconnect.JavaClass$MethodInfo.invoke(Unknown Source)
at sun.plugin2.liveconnect.JavaClass$MemberBundle.invoke(Unknown Source)
at sun.plugin2.liveconnect.JavaClass.invoke0(Unknown Source)
at sun.plugin2.liveconnect.JavaClass.invoke(Unknown Source)
at sun.plugin2.main.client.LiveConnectSupport$PerAppletInfo$DefaultInvocationDelegate.invoke(Unknown Source)
at sun.plugin2.main.client.LiveConnectSupport$PerAppletInfo$3.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at sun.plugin2.main.client.LiveConnectSupport$PerAppletInfo.doObjectOp(Unknown Source)
at sun.plugin2.main.client.LiveConnectSupport$PerAppletInfo$LiveConnectWorker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
Caused by: java.security.KeyException: Bad Data.
at sun.security.mscapi.RSACipher.encryptDecrypt(Native Method)
at sun.security.mscapi.RSACipher.doFinal(RSACipher.java:302)
提供者是SunMSCAPI
请帮我解决这个问题。 如果我的代码需要更新,请纠正我。