JAVA Signature Object - No installed provider supports this key: sun.security.rsa.RSAPrivateCrtKeyImpl

夙愿已清 提交于 2021-02-08 13:24:22

问题


I want to sign a file i created using a pair of RSA keys I created using key tool and the following command:

keytool -genkeypair -alias key -keyalg RSA -keysize 2048 -sigalg SHA256withRSA -validity 365 -keystore keystore.jks

I want to initialize my Signature object so I tried this:

PrivateKey privateKey = (PrivateKey) keyStore.getKey(PRIVATE_KEY_ALIAS,privateKeyPassword);
Signature signature = Signature.getInstance(SIGNATURE_ALGORITHM);
signature.initSign(privateKey);

But I got this exception:
No installed provider supports this key: sun.security.rsa.RSAPrivateCrtKeyImpl

Appreciate any help!


回答1:


You can't use SHA1withDSA with an RSA key. Change signature algorithm to SHA1withRSA or generate a DSA key instea



来源:https://stackoverflow.com/questions/41534827/java-signature-object-no-installed-provider-supports-this-key-sun-security-rs

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!