2
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

BouncyCastle: RSAのプライベートキーをパラメータから生成

Posted at

プライムとCRTパラメータが無い場合は、RsaKeyParameter(true) で生成すること!
それ以外はRsaPrivateCrtKeyParameters()(こっちの方が処理が速い)


        public static RsaKeyParameters ToRsaPrivateKey(this Jwk jwk)
        {
            System.Diagnostics.Debug.Assert(jwk.kty == Jose.Jwa.KeyType.RSA);

            // Private Key
            if( jwk.p == null )
            {
                return new RsaKeyParameters(true,
                    jwk.n, jwk.d);
            }
            return new RsaPrivateCrtKeyParameters(
                        jwk.n, // Modulus
                        jwk.e, // Pulbic Exponent
                        jwk.d, // Private Exponent  
                        jwk.p, // 1st Prime
                        jwk.q, // 2nd Prime
                        jwk.dp, // 1st Factor CTR exponent
                        jwk.dq, // 2nd Factor CTR exponent
                        jwk.qi  // 2nd Factor CTR exponent
                        );
            //TODO: "oth" (Other Prime Info パラメータ)はどうする?
                        
        }
2
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?