Ejemplo n.º 1
0
 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,
     });
 }
Ejemplo n.º 2
0
        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}");
            }
        }
Ejemplo n.º 3
0
        public static (RSA Rsa, RSAEncryptionPadding Padding) ToRSA(this RsaJwk jwk)
        {
            var rsa = RSA.Create(jwk.GetRSAParameters());

            return(rsa, jwk.GetPadding());
        }