Can any body help me in creating jwk from rsa public key like Manually create JWK from (RSA) PublicKey in java. Wanting to avoid Org.BouncyCastle or third party implementation
Asked
Active
Viewed 1,138 times
1 Answers
2
Have created JWK from public key as per following. IF any one have better suggestion then please let me know
using (var textReader = new StringReader(o.publickey))
{
var pubkeyReader = new PemReader(textReader);
RsaKeyParameters KeyParameters = (RsaKeyParameters)pubkeyReader.ReadObject();
var obj = new JwksKey
{
use = "sig",
kid = o.short_code,
e = Base64UrlEncoder.Encode(KeyParameters.Exponent.ToByteArrayUnsigned()),
n = Base64UrlEncoder.Encode(KeyParameters.Modulus.ToByteArrayUnsigned()),
kty = "RSA",
alg = "RS256"
};
objJwks.keys.Add(obj);
}
I want's couple of more thing from public key if possible instead of hardcoding it. two things are kty and alg. If it is possible then please let me know. I have private key available at this time of generation. do let me know if i can get kty and alg from them then i will use it. Thanks

Kamran Shahid
- 3,954
- 5
- 48
- 93