示例#1
0
        public HKeyExchange(int exponent, string modulus, string privateExponent) :
            this()
        {
            var keys = new RSAParameters();

            Exponent      = new BigInteger(exponent);
            keys.Exponent = Exponent.ToByteArray();

            Modulus      = BigInteger.Parse("0" + modulus, NumberStyles.HexNumber);
            keys.Modulus = Modulus.ToByteArray();
            Array.Reverse(keys.Modulus);

            if (!string.IsNullOrWhiteSpace(privateExponent))
            {
                PrivateExponent = BigInteger.Parse("0" + privateExponent, NumberStyles.HexNumber);
                keys.D          = PrivateExponent.ToByteArray();
                Array.Reverse(keys.D);

                GenerateDHPrimes(256);
                GenerateDHKeys(DHPrime, DHGenerator);
            }

            RSA = new RSACryptoServiceProvider();
            RSA.ImportParameters(keys);

            _blockSize = (RSA.KeySize -
                          RSA.LegalKeySizes[0].SkipSize) / 8;
        }
示例#2
0
        public HKeyExchange(int exponent, string modulus, string privateExponent)
        {
            Exponent = new BigInteger(exponent);
            Modulus  = BigInteger.Parse("0" + modulus, NumberStyles.HexNumber);

            var keys = new RSAParameters
            {
                Exponent = Exponent.ToByteArray(isBigEndian: true),
                Modulus  = Modulus.ToByteArray(isBigEndian: true)
            };

            if (!string.IsNullOrWhiteSpace(privateExponent))
            {
                PrivateExponent = BigInteger.Parse("0" + privateExponent, NumberStyles.HexNumber);
                keys.D          = PrivateExponent.ToByteArray(isBigEndian: true);

                GenerateDHPrimes(256);
                GenerateDHKeys(DHPrime, DHGenerator);
            }

            RSA = RSA.Create(keys);
        }