/** * Convenience wrapper around {@link ECKey#signedMessageToKey(String, String)}. If the key derived from the * signature is not the same as this one, throws a SignatureException. */ public void verifyMessage(String message, String signatureBase64) throws SignatureException { ECKey key = ECKey.signedMessageToKey(message, signatureBase64); if (!key.pub.equals(pub)) throw new SignatureException("Signature did not match for message"); }
/** * Convenience wrapper around {@link ECKey#signedMessageToKey(String, String)}. If the key derived from the * signature is not the same as this one, throws a SignatureException. */ public void verifyMessage(String message, String signatureBase64) throws SignatureException { ECKey key = ECKey.signedMessageToKey(message, signatureBase64); if (!key.pub.equals(pub)) throw new SignatureException("Signature did not match for message"); }
/** * Convenience wrapper around {@link ECKey#signedMessageToKey(String, String)}. If the key derived from the * signature is not the same as this one, throws a SignatureException. */ public void verifyMessage(String message, String signatureBase64) throws SignatureException { ECKey key = ECKey.signedMessageToKey(message, signatureBase64); if (!key.pub.equals(pub)) throw new SignatureException("Signature did not match for message"); } public void verifyMessage(byte [] message, byte [] signatureEncoded) throws SignatureException {
public void verifyMessage(byte [] message, byte [] signatureEncoded) throws SignatureException { ECKey key = ECKey.signedMessageToKey(message, signatureEncoded); if (!key.pub.equals(pub)) throw new SignatureException("Signature did not match for message"); } /**
/** * Convenience wrapper around {@link ECKey#signedMessageToKey(String, String)}. If the key derived from the * signature is not the same as this one, throws a SignatureException. */ public void verifyMessage(String message, String signatureBase64) throws SignatureException { ECKey key = ECKey.signedMessageToKey(message, signatureBase64); if (!key.pub.equals(pub)) throw new SignatureException("Signature did not match for message"); }
@Override public void verifyMessage(SignedMessage signedMessage) { try { ECKey pubKey = ECKey.signedMessageToKey( type.getSignedMessageHeader(), signedMessage.message, signedMessage.signature); byte[] expectedPubKeyHash = BitAddress.from(type, signedMessage.address).getHash160(); if (Arrays.equals(expectedPubKeyHash, pubKey.getPubKeyHash())) { signedMessage.status = SignedMessage.Status.VerifiedOK; } else { signedMessage.status = SignedMessage.Status.InvalidSigningAddress; } } catch (SignatureException e) { signedMessage.status = SignedMessage.Status.InvalidMessageSignature; } catch (AddressMalformedException e) { signedMessage.status = SignedMessage.Status.AddressMalformed; } }
@Override public void verifyMessage(SignedMessage signedMessage) { try { ECKey pubKey = ECKey.signedMessageToKey( type.getSignedMessageHeader(), signedMessage.message, signedMessage.signature); byte[] expectedPubKeyHash = BitAddress.from(type, signedMessage.address).getHash160(); if (Arrays.equals(expectedPubKeyHash, pubKey.getPubKeyHash())) { signedMessage.status = SignedMessage.Status.VerifiedOK; } else { signedMessage.status = SignedMessage.Status.InvalidSigningAddress; } } catch (SignatureException e) { signedMessage.status = SignedMessage.Status.InvalidMessageSignature; } catch (AddressMalformedException e) { signedMessage.status = SignedMessage.Status.AddressMalformed; } }
public static boolean verifyHash(Sha256Hash hash, byte [] pubkeyId, MasternodeSignature vchSig, StringBuilder strErrorRet) { ECKey pubkeyFromSig; try { pubkeyFromSig = ECKey.signedMessageToKey(hash, vchSig.getBytes()); if (pubkeyFromSig == null) { strErrorRet.append("Error recovering public key."); return false; } if (!Arrays.equals(pubkeyFromSig.getPubKeyHash(), pubkeyId)) { strErrorRet.append(String.format("Keys don't match: pubkey=%s, pubkeyFromSig=%s, hash=%s, vchSig=%s", HEX.encode(pubkeyId), HEX.encode(pubkeyFromSig.getPubKeyHash()), hash.toString(), Base64.toBase64String(vchSig.getBytes()))); return false; } return true; } catch (SignatureException x) { strErrorRet.append("exception: " + x.getMessage()); return false; } }
ECKey key = ECKey.signedMessageToKey(messageText, signatureText); Address gotAddress = key.toAddress(BitcoinNetwork.current().get()); if (signingAddress.equals(gotAddress)) {
private void validateSignature(Message msg) throws ValidationException, SignatureException { ECKey key = ECKey.signedMessageToKey( msg.getPayload(), msg.getSignature()); String senderAddress = msg.getSender(); String addressFromSignature = key.toAddress(PersistentUrls.getInstance().getCurrentNetworkParams()).toString(); if (!senderAddress.equals(addressFromSignature)) { throw new ValidationException("Signature is not well-formed"); } }
ECKey key = ECKey.signedMessageToKey(getMessage(), base64Signature); Address gotAddress = key.toAddress(MainNetParams.get());
@Test public void verifyMessage() throws Exception { // Test vector generated by Bitcoin-Qt. String message = "hello"; String sigBase64 = "HxNZdo6ggZ41hd3mM3gfJRqOQPZYcO8z8qdX2BwmpbF11CaOQV+QiZGGQxaYOncKoNW61oRuSMMF8udfK54XqI8="; Address expectedAddress = Address.fromBase58(MainNetParams.get(), "14YPSNPi6NSXnUxtPAsyJSuw3pv7AU3Cag"); ECKey key = ECKey.signedMessageToKey(message, sigBase64); Address gotAddress = key.toAddress(MainNetParams.get()); assertEquals(expectedAddress, gotAddress); }