Windows RSAPrivateKey (MSCAPI)
See original GitHub issueHi,
im loading a RSAPrivateKey on Windows with the following code:
KeyStore ks = KeyStore.getInstance("Windows-MY");
ks.load(null, null);
RSAPrivateKey privateKey = ks.getKey("someKeyAlias", null);
But then i get the following exception:
Exception in thread "main" java.lang.IllegalArgumentException: RSA signatures must be computed using an RSAPrivateKey.
The specified key of type sun.security.mscapi.RSAPrivateKey is not an RSAPrivateKey.
at io.jsonwebtoken.impl.crypto.RsaSigner.<init>(RsaSigner.java:34)
at io.jsonwebtoken.impl.crypto.DefaultSignerFactory.createSigner(DefaultSignerFactory.java:43)
at io.jsonwebtoken.impl.crypto.DefaultJwtSigner.<init>(DefaultJwtSigner.java:37)
at io.jsonwebtoken.impl.crypto.DefaultJwtSigner.<init>(DefaultJwtSigner.java:32)
at io.jsonwebtoken.impl.DefaultJwtBuilder.createSigner(DefaultJwtBuilder.java:339)
at io.jsonwebtoken.impl.DefaultJwtBuilder.compact(DefaultJwtBuilder.java:321)
Any idea why this is not compatible?
Issue Analytics
- State:
- Created 7 years ago
- Comments:11 (2 by maintainers)
Top Results From Across the Web
Old src/windows/classes/sun/security/mscapi/RSAPrivateKey ...
24 */ 25 26 package sun.security.mscapi; 27 28 import java.security.PrivateKey; 29 30 /** 31 * The handle for an RSA private key using...
Read more >java - Supplied key (sun.security.mscapi.CPrivateKey) is not a ...
Exception in thread "main" java.security.InvalidKeyException: Supplied key (sun.security.mscapi.CPrivateKey) is not a RSAPrivateKey instance ...
Read more >Supplied key (sun.security.mscapi.RSAPrivateKey) is not a ...
I am getting bellow error while trying to execute below method can some body help me out in this. Caused by: java.security.
Read more >RSA private key can't be read by microsoft crypt api
A common mistake is to import the key in big-endian. MS CAPI require litte-endian. Another solution is to use a JCE provider implementation...
Read more >sun/security/mscapi/SignedObjectChain.java fails on Windows
JDK-8176183 : sun/security/mscapi/SignedObjectChain.java fails on Windows ... signature accepts only RSAPrivateKey if ((key instanceof sun.security.mscapi.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
For others coming here with the same problem, I solved this by subclassing
io.jsonwebtoken.impl.DefaultJwtBuilder
and supplying my ownio.jsonwebtoken.impl.crypto.Signer
:This instance of
DefaultJwtBuilder
can then be used instead ofJwts.builder()
. The passed-inkey
in my case is an instance ofsun.security.mscapi.RSAPrivateKey
.Example use:
Works like a charm in my case, but YMMV.
Works like a charm in my case too. This needs to go to getting started section for externally stored keys - HSM