예제 #1
0
        public static string GetPublicKey(string privateKey)
        {
            var curve  = SecNamedCurves.GetByName("secp256k1");
            var domain = new ECDomainParameters(curve.Curve, curve.G, curve.N, curve.H);

            var d = new Org.BouncyCastle.Math.BigInteger(privateKey);
            var q = domain.G.Multiply(d);

            var publicKey = new ECPublicKeyParameters(q, domain);

            return(Base58Encoding.Encode(publicKey.Q.GetEncoded()));
        }
예제 #2
0
        public static string Sign(string privateKey, string content)
        {
            var curve  = SecNamedCurves.GetByName("secp256k1");
            var domain = new ECDomainParameters(curve.Curve, curve.G, curve.N, curve.H);

            var keyParameters = new
                                ECPrivateKeyParameters(new Org.BouncyCastle.Math.BigInteger(privateKey),
                                                       domain);

            ISigner signer = SignerUtilities.GetSigner("SHA-256withECDSA");

            signer.Init(true, keyParameters);
            signer.BlockUpdate(Encoding.ASCII.GetBytes(content), 0, content.Length);
            var signature = signer.GenerateSignature();

            return(Base58Encoding.Encode(signature));
        }