/** * Verify the signature as static * * @param data signed data * @param signature signature * @param hashed whether hashed data or not * @return verification result */ public static boolean verify(byte[] data, byte[] signature, boolean hashed) { return verify(data, signature, hashed, null); }
@Test public void testWalletSignAndVerify() throws IOException, InvalidCipherTextException { Wallet wallet = new Wallet(null, "tmp/temp", "temp.key", "Aa1234567890!"); byte[] plain = "test data 1111".getBytes(); log.debug("Plain data: " + new String(plain)); byte[] signature = wallet.sign(plain); log.debug("Signature: " + Hex.toHexString(signature)); boolean verifyResult = wallet.verify(plain, signature); log.debug("Verify Result: " + verifyResult); assertTrue(verifyResult); verifyResult = wallet.verifyHashedData(HashUtil.sha3(plain), signature); log.debug("Verify Result: " + verifyResult); assertTrue(verifyResult); verifyResult = Wallet.verify(HashUtil.sha3(plain), signature, true); log.debug("Verify Result: " + verifyResult); assertTrue(verifyResult); verifyResult = Wallet.verify(plain, signature, false); log.debug("Verify Result: " + verifyResult); assertTrue(verifyResult); verifyResult = Wallet.verify(plain, signature, false, wallet.getPubicKey()); log.debug("Verify Result: " + verifyResult); assertTrue(verifyResult); }
if (!Wallet.verify(getDataHashForSignHeader(header), Hex.decode(signature), true, adminPubKey)) { log.error("Signature is not valid.");
@Test public void testWalletConstructor() throws IOException, InvalidCipherTextException { DefaultConfig config = new DefaultConfig(); Wallet wallet = new Wallet(config); log.debug(wallet.toString()); assertNotNull(wallet); byte[] data = "sign data".getBytes(); byte[] signature = wallet.sign(data); boolean verifyResult = wallet.verify(data, signature); assertTrue(verifyResult); }
if (!Wallet.verify(dataToSign, Hex.decode(signature), false)) { log.error("Signature is not valid.");