@Test public void validSignatureInvalidPayload() { byte[] payload = "highlysensitiveinformation".getBytes(StandardCharsets.UTF_8); byte[] signature = signer.sign(payload); assertThat(verifier.verify("interceptedpayload".getBytes(StandardCharsets.UTF_8), signature)) .isFalse(); }
public boolean verify(byte[] payload, byte[] payloadSignature) { final Signature signature; try { signature = Signature.getInstance("SHA256withECDSA"); } catch (NoSuchAlgorithmException e) { throw new IllegalStateException( "Could not load ECDSA algorithm. Is bouncycastle on the classpath?"); } try { signature.initVerify(publicKey); } catch (InvalidKeyException e) { throw new IllegalStateException("Public key not an ECDSA key.", e); } try { signature.update(payload); return signature.verify(payloadSignature); } catch (SignatureException e) { logger.warn("Invalid signature.", e); return false; } }
ECDSA256Verifier { public boolean verify(byte[] payload, byte[] payloadSignature) { final Signature signature; try { signature = Signature.getInstance("SHA256withECDSA"); } catch (NoSuchAlgorithmException e) { throw new IllegalStateException( "Could not load ECDSA algorithm. Is bouncycastle on the classpath?"); } try { signature.initVerify(publicKey); } catch (InvalidKeyException e) { throw new IllegalStateException("Public key not an ECDSA key.", e); } try { signature.update(payload); return signature.verify(payloadSignature); } catch (SignatureException e) { logger.warn("Invalid signature.", e); return false; } } }
ECDSA256Verifier { public boolean verify(byte[] payload, byte[] payloadSignature) { final Signature signature; try { signature = Signature.getInstance("SHA256withECDSA"); } catch (NoSuchAlgorithmException e) { throw new IllegalStateException( "Could not load ECDSA algorithm. Is bouncycastle on the classpath?"); } try { signature.initVerify(publicKey); } catch (InvalidKeyException e) { throw new IllegalStateException("Public key not an ECDSA key.", e); } try { signature.update(payload); return signature.verify(payloadSignature); } catch (SignatureException e) { logger.warn("Invalid signature.", e); return false; } } @Inject  ECDSA256Verifier(SignerConfig config); }
ECDSA256Verifier { public boolean verify(byte[] payload, byte[] payloadSignature) { final Signature signature; try { signature = Signature.getInstance("SHA256withECDSA"); } catch (NoSuchAlgorithmException e) { throw new IllegalStateException( "Could not load ECDSA algorithm. Is bouncycastle on the classpath?"); } try { signature.initVerify(publicKey); } catch (InvalidKeyException e) { throw new IllegalStateException("Public key not an ECDSA key.", e); } try { signature.update(payload); return signature.verify(payloadSignature); } catch (SignatureException e) { logger.warn("Invalid signature.", e); return false; } } @Inject  ECDSA256Verifier(SignerConfig config); boolean verify(byte[] payload, byte[] payloadSignature); }
ECDSA256Verifier { public boolean verify(byte[] payload, byte[] payloadSignature) { final Signature signature; try { signature = Signature.getInstance("SHA256withECDSA"); } catch (NoSuchAlgorithmException e) { throw new IllegalStateException( "Could not load ECDSA algorithm. Is bouncycastle on the classpath?"); } try { signature.initVerify(publicKey); } catch (InvalidKeyException e) { throw new IllegalStateException("Public key not an ECDSA key.", e); } try { signature.update(payload); return signature.verify(payloadSignature); } catch (SignatureException e) { logger.warn("Invalid signature.", e); return false; } } @Inject  ECDSA256Verifier(SignerConfig config); boolean verify(byte[] payload, byte[] payloadSignature);  }