public override string ToString() { var b1 = R.ToByteArray(); var b2 = S.ToByteArray(); var buff = new byte[2 + b1.Length + b2.Length]; buff[0] = (byte)b1.Length; buff[1] = (byte)b2.Length; Buffer.BlockCopy(b1, 0, buff, 2, b1.Length); Buffer.BlockCopy(b2, 0, buff, 2 + b1.Length, b2.Length); return(Base58Encoding.Encode(buff)); }
public static string GetSignature(string privateKey, string message) { var curve = SecNamedCurves.GetByName("secp256r1"); var domain = new ECDomainParameters(curve.Curve, curve.G, curve.N, curve.H); //byte[] pkbytes = Base58Encoding.Decode(privateKey); //byte[] pkbytes = Base58Encoding.DecodeWithCheckSum(privateKey); byte[] pkbytes = Base58Encoding.DecodePrivateKey(privateKey); var keyParameters = new ECPrivateKeyParameters(new Org.BouncyCastle.Math.BigInteger(1, pkbytes), domain); ISigner signer = SignerUtilities.GetSigner("SHA-256withECDSA"); signer.Init(true, keyParameters); signer.BlockUpdate(Encoding.UTF8.GetBytes(message), 0, message.Length); var signature = signer.GenerateSignature(); var netformat = SignatureHelper.ConvertDerToP1393(signature); return(Base58Encoding.Encode(netformat)); }
public static string GetSignature(string privateKey, string message, string AccountId) { if (IsMono) { return(PortableSignatures.GetSignature(privateKey, message)); } 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; }