public RsaBlindingParameters(
            RsaKeyParameters	publicKey,
            BigInteger			blindingFactor)
        {
            if (publicKey.IsPrivate)
                throw new ArgumentException("RSA parameters should be for a public key");

            this.publicKey = publicKey;
            this.blindingFactor = blindingFactor;
        }
        /**
        * Initialise the factor generator
        *
        * @param param the necessary RSA key parameters.
        */
        public void Init(
            ICipherParameters param)
        {
            if (param is ParametersWithRandom)
            {
                ParametersWithRandom rParam = (ParametersWithRandom)param;

                key = (RsaKeyParameters)rParam.Parameters;
                random = rParam.Random;
            }
            else
            {
                key = (RsaKeyParameters)param;
                random = new SecureRandom();
            }

            if (key.IsPrivate)
                throw new ArgumentException("generator requires RSA public key");
        }
 public static RSAParameters ToRSAParameters(RsaKeyParameters rsaKey)
 {
     RSAParameters rp = new RSAParameters();
     rp.Modulus = rsaKey.Modulus.ToByteArrayUnsigned();
     if (rsaKey.IsPrivate)
         rp.D = ConvertRSAParametersField(rsaKey.Exponent, rp.Modulus.Length);
     else
         rp.Exponent = rsaKey.Exponent.ToByteArrayUnsigned();
     return rp;
 }
 public static RSA ToRSA(RsaKeyParameters rsaKey)
 {
     // TODO This appears to not work for private keys (when no CRT info)
     return CreateRSAProvider(ToRSAParameters(rsaKey));
 }
        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);
        }
        /**
        * initialise the RSA engine.
        *
        * @param forEncryption true if we are encrypting, false otherwise.
        * @param param the necessary RSA key parameters.
        */
        public void Init(
            bool				forEncryption,
            ICipherParameters	parameters)
        {
            if (parameters is ParametersWithRandom)
            {
                parameters = ((ParametersWithRandom) parameters).Parameters;
            }

            if (!(parameters is RsaKeyParameters))
                throw new InvalidKeyException("Not an RSA key");

            this.key = (RsaKeyParameters) parameters;
            this.forEncryption = forEncryption;
            this.bitSize = key.Modulus.BitLength;
        }
        /**
        * Initialise the blinding engine.
        *
        * @param forEncryption true if we are encrypting (blinding), false otherwise.
        * @param param         the necessary RSA key parameters.
        */
        public void Init(
            bool				forEncryption,
            ICipherParameters	param)
        {
            RsaBlindingParameters p;

            if (param is ParametersWithRandom)
            {
                ParametersWithRandom rParam = (ParametersWithRandom)param;

                p = (RsaBlindingParameters)rParam.Parameters;
            }
            else
            {
                p = (RsaBlindingParameters)param;
            }

            core.Init(forEncryption, p.PublicKey);

            this.forEncryption = forEncryption;
            this.key = p.PublicKey;
            this.blindingFactor = p.BlindingFactor;
        }
        /**
         * initialise the RSA engine.
         *
         * @param forEncryption true if we are encrypting, false otherwise.
         * @param param the necessary RSA key parameters.
         */
        public void Init(
            bool				forEncryption,
            ICipherParameters	param)
        {
            core.Init(forEncryption, param);

            if (param is ParametersWithRandom)
            {
                ParametersWithRandom rParam = (ParametersWithRandom)param;

                key = (RsaKeyParameters)rParam.Parameters;
                random = rParam.Random;
            }
            else
            {
                key = (RsaKeyParameters)param;
                random = new SecureRandom();
            }
        }