1
According to this function:
public boolean verify(Sha256Hash sigHash, ECDSASignature signature) {
return ECKey.verify(sigHash.getBytes(), signature, getPubKey());
}
I do not understand which must be the content of the variable sighash.
Here is my function where the creation of signature happend:
public ECDSASignature scriptSig(Receiver r) {
System.out.println("First step :\n");
System.out
.println("CREATION OF SCRIPTSIG-----OR----- OUTPUT TRANSACTION");
r = super.getReceiver();
Wallet rwallet = r.getReceiverWalletList().get(0);
BigInteger R = rwallet.getClientKey().getPrivKey();
System.out
.println("*******************************************************");
System.out.println(R);
BigInteger S = new BigInteger(r.getReceiverWalletList().get(0).getClientKey().getPubKey()); // i
// had
// .getPubkeyHash()
System.out
.println("*******************************************************");
System.out.println(S);
// constructs a signature with the given components
ECDSASignature receiverSig = new ECDSASignature(R, S);
return receiverSig;
}
and here i am trying to verify my signature:
sha256hash = new Sha256Hash(receiver.getReceiverWalletList()
.get(0).getClientKey().getPrivKeyBytes());
redeemerSignature = scriptSig(receiver);
.....
if (receiver.getReceiverWalletList().get(0).getClientKey()
.verify(sha256hash, redeemerSignature))
System.out.println("The transaction finished SUCCESSFULLY");
else
System.out
.println("The transaction finished UNSUCCESSFULLY");
I think i my problem is the right input in sha256hash = new Sha256Hash(...) instance.
Any help?
I actually created my ECDSASignature object by using the sign(Sha256 input). My input was : Sha256Hash input=new Sha256Hash(rwallet.getClientKey().getPrivKeyBytes()); And then in verification function in both ways first with:rKey .verify(sha256hash, redeemerSignature)) and second with : ECKey .verify(sha256hash.getBytes(), redeemerSignature, rKey.getPubKey())) works correct. – gtopal – 2015-12-30T07:58:48.023
Eventually, @Konstantinos you are right about the thing that I have to sign a message and not the getPrivKeyBytes() result,as it will reveal information about my private key. I think the best thing is to sign a Transaction object,but for my program's functionality requirements...i will sign a message( which in fact will be a String). – gtopal – 2016-01-09T20:39:42.360