7

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!

2
  • What is SIGNATURE_ALGORITHM value? Jan 8, 2017 at 19:29
  • Sorry I forgot about that one private static final String SIGNATURE_ALGORITHM = "SHA1withDSA";
    – Dor Mesica
    Jan 8, 2017 at 20:07

1 Answer 1

12

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.