public static RSA ToRSA(RsaPrivateCrtKeyParameters privKey)
 {
     return CreateRSAProvider(ToRSAParameters(privKey));
 }
 public static RSAParameters ToRSAParameters(RsaPrivateCrtKeyParameters privKey)
 {
     RSAParameters rp = new RSAParameters();
     rp.Modulus = privKey.Modulus.ToByteArrayUnsigned();
     rp.Exponent = privKey.PublicExponent.ToByteArrayUnsigned();
     rp.P = privKey.P.ToByteArrayUnsigned();
     rp.Q = privKey.Q.ToByteArrayUnsigned();
     rp.D = ConvertRSAParametersField(privKey.Exponent, rp.Modulus.Length);
     rp.DP = ConvertRSAParametersField(privKey.DP, rp.P.Length);
     rp.DQ = ConvertRSAParametersField(privKey.DQ, rp.Q.Length);
     rp.InverseQ = ConvertRSAParametersField(privKey.QInv, rp.Q.Length);
     return rp;
 }
        public static AsymmetricCipherKeyPair GetRsaKeyPair(
            RSAParameters rp)
        {
            BigInteger modulus = new BigInteger(1, rp.Modulus);
            BigInteger pubExp = new BigInteger(1, rp.Exponent);

            RsaKeyParameters pubKey = new RsaKeyParameters(
                false,
                modulus,
                pubExp);

            RsaPrivateCrtKeyParameters privKey = new RsaPrivateCrtKeyParameters(
                modulus,
                pubExp,
                new BigInteger(1, rp.D),
                new BigInteger(1, rp.P),
                new BigInteger(1, rp.Q),
                new BigInteger(1, rp.DP),
                new BigInteger(1, rp.DQ),
                new BigInteger(1, rp.InverseQ));

            return new AsymmetricCipherKeyPair(pubKey, privKey);
        }