Beispiel #1
0
        public override void ExtractParameters()
        {
            if (privateKey == null)
            {
                var parameters = ExtractParameters(blob);
                var d          = BigInteger.Zero.AddUnsignedBigEndian(parameters);

                keySize = (int)BigInteger.Log(d, 2);
                if (keySize > 160 && keySize < 256)
                {
                    keySize = 256;
                }
                if (keySize > 256 && keySize < 384)
                {
                    keySize = 384;
                }
                if (keySize > 384 && keySize < 521)
                {
                    keySize = 521;
                }

                var ecdsa = new ECDSAManaged(keySize);
                var curve = ecdsa.Curve;
                privateKey = new ECDiffieHellmanManagedPrivateKey(curve, d);
                ecdsa.ImportParameters(privateKey);
                Algorithm = ecdsa;
            }
        }
Beispiel #2
0
        private static bool VerifyECDSA(byte[] sig, byte[] h, PacketReader pr)
        {
            var keyAlgorithm = pr.ReadStringAsString();
            var keySize      = int.Parse(keyAlgorithm.Substring(keyAlgorithm.Length - 3));
            var keyInfo      = pr.ReadString();

            var ecdsa = new ECDSAManaged(keySize);

            ecdsa.ImportParameters(new ECDiffieHellmanManagedPublicKey(keyInfo));
            return(ecdsa.VerifyHash(h, sig));
        }