public Transaction(string reciepient, double amount, ECDSA ec, string message = "") { TransactionIssuer = ec.ExportPubKey; Reciepient = reciepient; Amount = amount; IsuueTime = DateTime.UtcNow; TxHash = ComputeObjectHash(); //Signture = ec.Sign(TxHash).ToByteArray(StringEncoding.Base64).ToBase58Check(); Signture = ec.Sign(TxHash); ScriptPubKey = $"{Signture};{TransactionIssuer}"; ScriptSig = $"{ScriptPubKey};CheckSig;IsOne"; }
public void TestSignature() { var input = Encoding.UTF8.GetBytes("Hello!"); var ecdsa = new ECDSA(new DefaultRandomGenerator()); ecdsa.Init(new ECCipherParameters(Secp256R1.Parameters, PrivateKey)); var signature = ecdsa.Sign(input, new SHA256Digest(SHA256Digest.Mode.SHA256)); var result = ecdsa.Verify(input, signature, new SHA256Digest(SHA256Digest.Mode.SHA256)); Assert.True(result); }
public override byte[] DoSign(byte[] ske, out int hashAlgo, out int signAlgo) { hashAlgo = this.hashAlgo; byte[] hv = Hash(hashAlgo, ske); if (skey is RSAPrivateKey) { RSAPrivateKey rk = skey as RSAPrivateKey; signAlgo = SSL.RSA; byte[] head; switch (hashAlgo) { case SSL.MD5SHA1: head = null; break; case SSL.SHA1: head = RSA.PKCS1_SHA1; break; case SSL.SHA224: head = RSA.PKCS1_SHA224; break; case SSL.SHA256: head = RSA.PKCS1_SHA256; break; case SSL.SHA384: head = RSA.PKCS1_SHA384; break; case SSL.SHA512: head = RSA.PKCS1_SHA512; break; default: throw new Exception(); } return(RSA.Sign(rk, head, hv)); } else if (skey is ECPrivateKey) { ECPrivateKey ek = skey as ECPrivateKey; signAlgo = SSL.ECDSA; return(ECDSA.Sign(ek, null, hv)); } else { throw new Exception("NYI"); } }