Esempio n. 1
0
        public static bool VerifySignature(byte[] message, byte[] signature, byte[] pubkey)
        {
            //unity dotnet不完整,不能用dotnet自带的ecdsa
            var PublicKey = ThinNeo.Cryptography.ECC.ECPoint.DecodePoint(pubkey, ThinNeo.Cryptography.ECC.ECCurve.Secp256r1);
            var ecdsa     = new ThinNeo.Cryptography.ECC.ECDsa(PublicKey);
            var b1        = signature.Take(32).Reverse().Concat(new byte[] { 0x00 }).ToArray();
            var b2        = signature.Skip(32).Reverse().Concat(new byte[] { 0x00 }).ToArray();
            var num1      = new BigInteger(b1);
            var num2      = new BigInteger(b2);
            var hash      = sha256.ComputeHash(message);

            return(ecdsa.VerifySignature(hash, num1, num2));
            //var PublicKey = ThinNeo.Cryptography.ECC.ECPoint.DecodePoint(pubkey, ThinNeo.Cryptography.ECC.ECCurve.Secp256r1);
            //var usepk = PublicKey.EncodePoint(false).Skip(1).ToArray();

            ////byte[] first = { 0x45, 0x43, 0x53, 0x31, 0x20, 0x00, 0x00, 0x00 };
            ////usepk = first.Concat(usepk).ToArray();

            ////using (System.Security.Cryptography.CngKey key = System.Security.Cryptography.CngKey.Import(usepk, System.Security.Cryptography.CngKeyBlobFormat.EccPublicBlob))
            ////using (System.Security.Cryptography.ECDsaCng ecdsa = new System.Security.Cryptography.ECDsaCng(key))

            //using (var ecdsa = System.Security.Cryptography.ECDsa.Create(new System.Security.Cryptography.ECParameters
            //{
            //    Curve = System.Security.Cryptography.ECCurve.NamedCurves.nistP256,
            //    Q = new System.Security.Cryptography.ECPoint
            //    {
            //        X = usepk.Take(32).ToArray(),
            //        Y = usepk.Skip(32).ToArray()
            //    }
            //}))
            //{
            //    var hash = sha256.ComputeHash(message);
            //    return ecdsa.VerifyHash(hash, signature);
            //}
        }
Esempio n. 2
0
            public bool VerifyHash(byte[] hash, byte[] signature)
            {
                var b1   = signature.Take(32).Reverse().Concat(new byte[] { 0x00 }).ToArray();
                var b2   = signature.Skip(32).Reverse().Concat(new byte[] { 0x00 }).ToArray();
                var num1 = new BigInteger(b1);
                var num2 = new BigInteger(b2);

                return(ecdsa.VerifySignature(hash, num1, num2));
            }
Esempio n. 3
0
        public static bool VerifySignature(byte[] message, byte[] signature, byte[] pubkey)
        {
            //unity dotnet不完整,不能用dotnet自带的ecdsa
            var PublicKey = ThinNeo.Cryptography.ECC.ECPoint.DecodePoint(pubkey, ThinNeo.Cryptography.ECC.ECCurve.Secp256r1);
            var ecdsa     = new ThinNeo.Cryptography.ECC.ECDsa(PublicKey);
            var b1        = signature.Take(32).Reverse().Concat(new byte[] { 0x00 }).ToArray();
            var b2        = signature.Skip(32).Reverse().Concat(new byte[] { 0x00 }).ToArray();
            var num1      = new BigInteger(b1);
            var num2      = new BigInteger(b2);
            var hash      = sha256.ComputeHash(message);

            return(ecdsa.VerifySignature(hash, num1, num2));
        }