/** * Verify the signature with plain data. * * @param data plain data for signed * @param signature signature * @return verification result */ public boolean verify(byte[] data, byte[] signature) { ECKey.ECDSASignature sig = new ECKey.ECDSASignature(signature); return key.verify(HashUtil.sha3(data), sig); }
/** * Verifies the given ASN.1 encoded ECDSA signature against a hash using the public key. * * @param data Hash of the data to verify. * @param signature signature. * @param pub The public key bytes to use. * @return - */ public static boolean verify(byte[] data, byte[] signature, byte[] pub) { return verify(data, ECDSASignature.decodeFromDER(signature), pub); }
private void testProviderRoundTrip(Provider provider) { ECKey key = new ECKey(provider, secureRandom); String message = "The quick brown fox jumps over the lazy dog."; byte[] input = HashUtil.sha3(message.getBytes()); ECDSASignature sig = key.sign(input); assertTrue(sig.validateComponents()); assertTrue(key.verify(input, sig)); }
/** * Get the public key. * * @return public key */ byte[] getPubKey() throws SignatureException { ECKey.ECDSASignature ecdsaSignature = new ECKey.ECDSASignature(this.signature); ECKey ecKeyPub = ECKey.signatureToKey(this.header.getHashForSigning(), ecdsaSignature); return ecKeyPub.getPubKey(); }
/** * Verify the signature with hashed data. * * @param hashedData hashed Data * @param signature signature * @return verification result */ boolean verifyHashedData(byte[] hashedData, byte[] signature) { ECKey.ECDSASignature sig = new ECKey.ECDSASignature(signature); return key.verify(hashedData, sig); }
/** * Account Constructor. * - generate wallet with new key */ public Account() { this.key = new ECKey(); this.address = this.key.getAddress(); }
private Sha3Hash(byte[] data, boolean hashed) { if (hashed) { this.data = data; } else { this.data = HashUtil.sha3(data); } }
/** * Compute the key that signed the given signature. * * @param messageHash 32-byte hash of message * @param signatureBase64 Base-64 encoded signature * @return ECKey */ public static ECKey signatureToKey(byte[] messageHash, String signatureBase64) throws SignatureException { final byte[] keyBytes = signatureToKeyBytes(messageHash, signatureBase64); return ECKey.fromPublicOnly(keyBytes); }
/** * SHA1 Hash Method. * * @param input data * @return hashed data */ public static byte[] sha1(byte[] input) { return hash(input, HASH_SHA_1_ALGORITHM_NAME); }
/** * Get public key * * @return public key */ public byte[] getPubicKey() { return key.getPubKey(); }
/** * Compute the address of the key that signed the given signature. * * @param messageHash 32-byte hash of message * @param signatureBase64 Base-64 encoded signature * @return 20-byte address */ public static byte[] signatureToAddress(byte[] messageHash, String signatureBase64) throws SignatureException { return computeAddress(signatureToKeyBytes(messageHash, signatureBase64)); }
/** * Generates the NodeID based on this key, that is the public key without first format byte */ public byte[] getNodeId() { if (nodeId == null) { nodeId = pubBytesWithoutFormat(this.pub); } return nodeId; }
/** * Gets the address form of the public key. * * @return 20-byte address */ public byte[] getAddress() { if (pubKeyHash == null) { pubKeyHash = computeAddress(this.pub); } return pubKeyHash; }
/** * Compute the key that signed the given signature. * * @param messageHash 32-byte hash of message * @param signatureBin Binary encoded signature * @return ECKey */ public static ECKey signatureToKey(byte[] messageHash, byte[] signatureBin) throws SignatureException { final byte[] keyBytes = signatureToKeyBytes(messageHash, signatureBin); return ECKey.fromPublicOnly(keyBytes); }
/** * SHA256 Hash Method. * * @param input - data for hashing * @return - sha256 hash of the data */ static byte[] sha256(byte[] input) { return hash(input, HASH_SHA_256_ALGORITHM_NAME); }
/** * SHA3(Keccak256) Hash Method. * * @param input data * @return hashed data */ public static byte[] sha3(byte[] input) { return hash(input, HASH_256_ALGORITHM_NAME); }
/** * The hash method for supporting many algorithms. * * @param input data for hashing. * @param algorithm algorithm for hashing. ex) "KECCAK-256", "SHA-256", "SHA3-256", "SHA-1" * @return hashed data. */ public static byte[] hash(byte[] input, String algorithm) { return hash(input, algorithm, false); }