public void testSignAndVerify1() { string fullURL = "https://btcpaytest.indiesquare.net/tokens"; //byte[] dataBytes = Encoding.UTF8.GetBytes(fullURL); String hash = KeyUtils.Sha256Hash(fullURL); var dataBytes = KeyUtils.hexToBytes(hash); byte[] sigBytes = _ecKey.Sign(dataBytes); string sigStr = KeyUtils.bytesToHex(sigBytes); Assert.IsTrue(_ecKey.Verify(dataBytes, sigBytes)); }
public void TestSignatures() { // Test that we can construct an ECKey from a private key (deriving the public from the private), then signing // a message with it. var privkey = new BigInteger(1, Hex.Decode("180cb41c7c600be951b5d3d0a7334acc7506173875834f7a6c4c786a28fcbb19")); var key = new EcKey(privkey); var message = new byte[32]; // All zeroes. var output = key.Sign(message); Assert.True(key.Verify(message, output)); // Test interop with a signature from elsewhere. var sig = Hex.Decode("3046022100dffbc26774fc841bbe1c1362fd643609c6e42dcb274763476d87af2c0597e89e022100c59e3c13b96b316cae9fa0ab0260612c7a133a6fe2b3445b6bf80b3123bf274d"); Assert.True(key.Verify(message, sig)); }
public void TestSignatures() { // Test that we can construct an ECKey from a private key (deriving the public from the private), then signing // a message with it. var privkey = new BigInteger(1, Hex.Decode("180cb41c7c600be951b5d3d0a7334acc7506173875834f7a6c4c786a28fcbb19")); var key = new EcKey(privkey); var message = new byte[32]; // All zeroes. var output = key.Sign(message); Assert.IsTrue(key.Verify(message, output)); // Test interop with a signature from elsewhere. var sig = Hex.Decode("3046022100dffbc26774fc841bbe1c1362fd643609c6e42dcb274763476d87af2c0597e89e022100c59e3c13b96b316cae9fa0ab0260612c7a133a6fe2b3445b6bf80b3123bf274d"); Assert.IsTrue(key.Verify(message, sig)); }
public TransactionSignature CalculateSignature(Transaction transaction, TransactionOutPoint outPoint, EcKey key, Script.Script redeemScript, Transaction.SigHash hashType) { // at the moment only signing all the outputs is supported Thrower.If(hashType != Transaction.SigHash.All).Throw <TransactionException>("Only SigHash type 'All' supported"); //// clone the transaction and clear all the inputs //// only the inputs for the equivalent output needs to be present for signing var signTx = transaction.Clone(); signTx.Inputs.ForEach(input => input.ScriptBytes = Enumerable.Empty <byte>().ToArray()); // set the redeem script and clear it of 'OP_CODESEPARATOR' var connectedScript = redeemScript.GetProgram(); var redeemConnectedScript = Script.Script.RemoveAllInstancesOfOp(connectedScript, ScriptOpCodes.OP_CODESEPARATOR); signTx.FindInput(outPoint).ScriptBytes = redeemConnectedScript; // serialize then hash the transaction to HEX and sign it. var trxHex = this.Serializer.ToHex(signTx, hashType); var hash = CryptoUtil.Sha256HashTwice(CryptoUtil.ConvertHex(trxHex)); return(new TransactionSignature(key.Sign(hash), hashType)); }
public static String Sign(EcKey ecKey, String input) { String hash = Sha256Hash(input); return(BytesToHex(ecKey.Sign(HexToBytes(hash)))); }