예제 #1
0
        public static bool VerifyAccountSignature(string message, string accountId, string signature)
        {
            if (string.IsNullOrWhiteSpace(message) || !ValidateAccountId(accountId) || string.IsNullOrWhiteSpace(signature))
            {
                return(false);
            }
            var publicKeyBytes = Base58Encoding.DecodeAccountId(accountId);

            return(VerifySignature(message, publicKeyBytes, signature));
        }
예제 #2
0
        public static bool ValidateAccountId(string AccountId)
        {
            try
            {
                if (AccountId[0] != 'L')
                {
                    return(false);
                }

                Base58Encoding.DecodeAccountId(AccountId);
                return(true);
            }
            catch
            {
                return(false);
            }
        }
예제 #3
0
        private static bool VerifySignature(string message, string AccountId, string signature)
        {
            try
            {
                var signatureBytes = Base58Encoding.Decode(signature);
                var publicKeyBytes = Base58Encoding.DecodeAccountId(AccountId);

                var result = Neo.Cryptography.Crypto.Default.VerifySignature(Encoding.UTF8.GetBytes(message), signatureBytes, publicKeyBytes);

                return(result);
            }
            catch (Exception ex)
            {
                _log?.LogError("VerifySignature failed: " + ex.Message);
                return(false);
            }
        }
        public static string GetSignature(string privateKey, string message, string AccountId)
        {
            var publicKeyBytes  = Base58Encoding.DecodeAccountId(AccountId);
            var privateKeyBytes = Base58Encoding.DecodePrivateKey(privateKey);

            //var signature = Neo.Cryptography.Crypto.Default.Sign(Encoding.UTF8.GetBytes(message), privateKeyBytes, publicKeyBytes);
            //return Base58Encoding.Encode(signature);

            Neo.Cryptography.ECC.ECDsa sa = new Neo.Cryptography.ECC.ECDsa(privateKeyBytes, Neo.Cryptography.ECC.ECCurve.Secp256r1);
            var sigInts = sa.GenerateSignature(Encoding.ASCII.GetBytes(message));

            var sh        = new SignatureHolder(sigInts);
            var signature = sh.ToString();

            //var vrt = VerifySignature(message, AccountId, signature);

            return(signature);
        }
        private static bool VerifySignature(string message, string AccountId, string signature)
        {
            try
            {
                var signatureBytes = Base58Encoding.Decode(signature);
                var publicKeyBytes = Base58Encoding.DecodeAccountId(AccountId);

                //return Neo.Cryptography.Crypto.Default.VerifySignature(Encoding.UTF8.GetBytes(message), signatureBytes, publicKeyBytes);
                Neo.Cryptography.ECC.ECDsa sa = new Neo.Cryptography.ECC.ECDsa(Neo.Cryptography.ECC.ECPoint.FromBytes(publicKeyBytes, Neo.Cryptography.ECC.ECCurve.Secp256r1));
                var sh = new SignatureHolder(signature);
                return(sa.VerifySignature(Encoding.ASCII.GetBytes(message), sh.R, sh.S));
            }
            catch (Exception ex)
            {
                _log.LogError("VerifySignature failed: " + ex.Message);
                return(false);
            }
        }