Creating a PrivateKey from a String
Issue #31
new
Can you please provide an example of how to create a PrivateKey when you have a private key as a String;
Eventually, need to use the PrivateKey to sign the JWT;
PrivateKey myKey = "abcd"; // this is where the trouble is.. converting a string to the PrivateKey object
JsonWebSignature jws = new JsonWebSignature(); jws.setKey(myKey.getPrivateKey());
Comments (4)
-
repo owner -
I had some code that already read a jwk.json file. This was my workaround: but I used this tool rsa-pem-to-jwk to convert a pem to a jwk file that jose4j could read directly. I don't use node.js typically but it was quite easy to hack a script together that could convert the private key to a jwk.json file.
-
repo owner Did you create this issue originally @Magnus_Mollyware ?
-
Nope, it was someone else.
- Log in to comment
It depends on how the key is encoded and if it's encrypted or not. And beyond that, I honestly don't know.
You might want to look at http://stackoverflow.com/questions/8454677/create-privatekey-and-publickey-from-a-string-base64-encoding-with-der-format or other similar http://stackoverflow.com/questions/8454677/create-privatekey-and-publickey-from-a-string-base64-encoding-with-der-format
Generally using openssl to get it into a format that is easy to use in Java is where I'd go with it. The link above talks about PKCS
#8. But another thing to consider is maybe converting to PKCS#12which java can read as a keystore.