示例#1
0
        private void calcPubKey(bool comp, secp256k1Wrap secp256k1)
        {
            //ECPoint point = ecParams.G.Multiply(new BigInteger(1, privKey));
            this.pubKey = HexString.ToByteArray(secp256k1.CreatePubKey(HexString.FromByteArray(privKey)));

            compress(comp);
        }
示例#2
0
        public CSPRNGServer()
        {
            Console.WriteLine(Directory.GetCurrentDirectory());

            //the CSPRNG is seeded using a thread based seed generator in BC
            byte[] seedarray = new byte[512];
            digest = new Sha512Digest();
            gen    = new DigestRandomGenerator(digest);


            //add some additional entropy to the seed
            for (int i = 0; i < 48; i++)
            {
                gen.AddSeedMaterial(DateTime.Now.Ticks);
            }

            int threadId = System.Threading.Thread.CurrentThread.ManagedThreadId;

            gen.AddSeedMaterial(threadId);

            instcheck++;

            secp256k1 = new secp256k1Wrap();


            //load database commands from files
        }
示例#3
0
        public BIP32(string privKey, string pubKey, secp256k1Wrap psecp256k1)
        {
            secp256k1 = psecp256k1;

            byte[] privKeyRaw = parseKey(privKey);
            byte[] pubKeyRaw = parseKey(pubKey);

            Initialise(privKeyRaw, pubKeyRaw);

            

        }
示例#4
0
        public static string GetSignature2(string key, string hashForSigning, secp256k1Wrap secp256k1)
        {
            string sig = secp256k1.Sign(key, hashForSigning);

            byte[] b = HexString.ToByteArray(sig);

            int slen  = b[1];
            int srlen = b[3];
            int sslen = b[5 + srlen];
            int ssend = 6 + srlen + sslen;
            int pad   = ((b.Length - ssend) * 2);

            sig = sig.Remove(sig.Length - pad);
            sig = sig + "01";

            return(sig);
        }
示例#5
0
        public BIP32(string sKey, secp256k1Wrap psecp256k1 )
        {
            secp256k1 = psecp256k1;

            SHA256 sha = SHA256.Create();

            byte[] decoded = Base58String.ToByteArray(sKey);

            if (decoded.Length != 82) throw new Exception("Not enough data");

            byte[] checksum = decoded.Skip(78).Take(4).ToArray();

            byte[] bytes = decoded.Take(78).ToArray();

            byte[] hash = sha.ComputeHash(sha.ComputeHash(bytes));

            if (hash[0] != checksum[0] || hash[1] != checksum[1] || hash[2] != checksum[2] || hash[3] != checksum[3])
            {
                throw new Exception("Invalid checksum");
            }

            Initialise(bytes);
        }
示例#6
0
 public ECKeyPair(Byte[] privKey, Byte[] pubKey = null, Boolean compressed = false, bool nopublickey = false, secp256k1Wrap secp256k1 = null)
 {
     this.privKey = privKey;
     if (pubKey != null)
     {
         this.pubKey       = pubKey;
         this.isCompressed = pubKey.Length <= 33;
     }
     else
     {
         if (!nopublickey)
         {
             calcPubKey(compressed, secp256k1);
         }
     }
 }
示例#7
0
 public BIP32(secp256k1Wrap psecp256k1)
 {
     secp256k1 = psecp256k1;
 }