Exemplo n.º 1
0
        /// <summary>
        /// Generates the key pair.
        /// </summary>
        /// <returns>The key pair.</returns>
        /// <param name="brainKey">Brain key.</param>
        public KeyPair GenerateKeyPair(string brainKey = null)
        {
            string brain_key = brainKey;

            if (brain_key == null)
            {
                brain_key = String.Join(" ", bip39.GenerateMnemonic(160, BIP39Wordlist.English).Split('\r').AsEnumerable <string>().Select(a =>
                {
                    return(a.Trim());
                }).ToArray()).Trim();
            }
            byte[]            private_key_bytes = Hash.SHA256(brain_key + " " + 0);
            Crypto.PrivateKey privateKey        = Crypto.PrivateKey.FromBytes(private_key_bytes);

            return(new KeyPair()
            {
                BrainKey = brain_key,
                PrivateKey = privateKey.ToWif(),
                PublicKey = privateKey.GetPublicKey().ToString()
            });
        }
Exemplo n.º 2
0
        /// <summary>
        /// ECDSA with secp256k1
        /// </summary>
        /// <param name="message">message</param>
        /// <param name="privateKey">Private key</param>
        /// <returns></returns>
        public static Signature SignBytes(byte[] message, PrivateKey privateKey)
        {
            var sign = Secp256K1Manager.SignCompressedCompact(Sha256Manager.GetHash(message), privateKey.D.ToByteArrayUnsigned(true));

            return(Signature.FromBytes(sign));
        }
Exemplo n.º 3
0
 /// <summary>
 /// Sign a string
 /// </summary>
 /// <returns>The string.</returns>
 /// <param name="message">Message.</param>
 /// <param name="privateKey">Private key.</param>
 public static Signature SignString(string message, PrivateKey privateKey)
 {
     return(SignBytes(Encoding.UTF8.GetBytes(message), privateKey));
 }