Пример #1
0
        /// <summary>VerifySign verify ASN.1 DER encoded signature using given public key with data</summary>
        public static bool VerifySign(AccountPublicKey publicKey, byte[] sign, byte[] data)
        {
            var decodedSign = Asn1DecodeSign(sign);
            var ecdsa       = loadECDSAFromPublicKey(publicKey);

            return(ecdsa.VerifyHash(data, decodedSign));
        }
Пример #2
0
        // Set the data path of the account address and private key
        /// <summary>Set the data path of the account address and private key</summary>
        /// <param name="path">the folder contains user's address and private key</param>
        /// <returns>return true if set success</returns>
        public bool SetAccountByPath(string path)
        {
            try
            {
                using (StreamReader sr = new StreamReader(path + "/address"))
                {
                    var addr = sr.ReadToEnd();
                    this.account.Address = addr;
                }
                using (StreamReader sr = new StreamReader(path + "/private.key"))
                {
                    var privkeyStr = sr.ReadToEnd();
                    var privkey    = new AccountPrivateKey();
                    privkey.ParseJSON(privkeyStr);
                    this.account.PrivateKey = privkey;
                }
                using (StreamReader sr = new StreamReader(path + "/public.key"))
                {
                    var pubkeyStr = sr.ReadToEnd();
                    var pubkey    = new AccountPublicKey();
                    pubkey.ParseJSON(pubkeyStr);
                    this.account.PublicKey = pubkey;
                }
            }
            catch (Exception e)
            {
                Console.WriteLine("Exception in SetAccountByPath, err=" + e);
                return(false);
            }

            return(true);
        }
Пример #3
0
        private static ECDsa loadECDSAFromPublicKey(AccountPublicKey publicKey)
        {
            var param = new ECParameters
            {
                Curve = ECCurve.NamedCurves.nistP256,
                Q     = new ECPoint
                {
                    X = XConvert.GetECBytesFromBigInteger(publicKey.X),
                    Y = XConvert.GetECBytesFromBigInteger(publicKey.Y),
                },
            };

            return(ECDsa.Create(param));
        }
Пример #4
0
        private Pb.UtxoOutput SelectUTXO(string bcname, string address, AccountPublicKey pubkey, BigInteger amount)
        {
            var reqData = new Pb.UtxoInput()
            {
                Header    = GetDefaultHeader(),
                Bcname    = bcname,
                Address   = address,
                TotalNeed = amount.ToString(),
                NeedLock  = false,
            };
            var res = client.SelectUTXO(reqData);

            if (res.Header.Error != Pb.XChainErrorEnum.Success)
            {
                Console.WriteLine("Error in select UTXO, errcode=" + (int)res.Header.Error + ", logid=" + reqData.Header.Logid);
                return(null);
            }
            return(res);
        }