0

I have private key as 'cUN9LNcEC54HAbWAwUs6coPSc72TcQYzxf4qSqdHJPVKSapeHzFj' and payload as 'hello', now how to create the signature for this payload using private key in java with bitcoinj library?

public static String createSignature1(String payload) throws NoSuchAlgorithmException {
    ECKey pubKey = ECKey.fromPrivate(publicKeyHash("cUN9LNcEC54HAbWAwUs6coPSc72TcQYzxf4qSqdHJPVKSapeHzFj".getBytes(StandardCharsets.UTF_8)));
    ECKey.ECDSASignature signatureBase64 = pubKey.sign(Sha256Hash.wrap(DigestUtils.sha256(Arrays.toString(payload.getBytes(UTF_8)))));
    Log.info("Signature is : " + signatureBase64);
    Log.info("Base64 encoded Signature is : " + byteArrayToHex(Base64.getEncoder().encode(signatureBase64.encodeToDER())));
    return byteArrayToHex(signatureBase64.encodeToDER());
}

The above code returning invalid signature.

Bhala T R
  • 33
  • 6
  • https://bitcoin.stackexchange.com/questions/50562/how-to-sign-raw-transaction-given-a-private-key-and-sha-hash-in-java?rq=1 answer helped me to achieve this. – Bhala T R Jan 21 '21 at 19:08
  • https://bitcoin.stackexchange.com/a/50579/100550 helped and saved time, thanks a lot @sven-williamson – Bhala T R Jan 21 '21 at 19:10

0 Answers0