public static RSAParameters GetRSAParameters(this RsaJwk jwk) { return(new RSAParameters { D = jwk.PrivateExponent, DP = jwk.FirstFactorCrtExponent, DQ = jwk.SecondFactorCrtExponent, Exponent = jwk.Exponent, InverseQ = jwk.FirstCrtCoefficient, Modulus = jwk.Modulus, P = jwk.FirstPrimeFactor, Q = jwk.SecondPrimeFactor, }); }
public static RSAEncryptionPadding GetPadding(this RsaJwk jwk) { switch (jwk.Algorithm) { case "RSA-OAEP": return(RSAEncryptionPadding.OaepSHA1); case "RSA-OAEP-256": return(RSAEncryptionPadding.OaepSHA256); case "RSA-OAEP-384": return(RSAEncryptionPadding.OaepSHA384); case "RSA-OAEP-512": return(RSAEncryptionPadding.OaepSHA512); default: throw new InvalidDataException($"Unsupported JWK algorithm {jwk.Algorithm}"); } }
public static (RSA Rsa, RSAEncryptionPadding Padding) ToRSA(this RsaJwk jwk) { var rsa = RSA.Create(jwk.GetRSAParameters()); return(rsa, jwk.GetPadding()); }