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.