@Test public void signedCanBeVerified() { byte[] payload = "highlysensitiveinformation".getBytes(StandardCharsets.UTF_8); byte[] signature = signer.sign(payload); assertThat(verifier.verify(payload, signature)).isTrue(); }
public byte[] sign(byte[] payload) { 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.initSign(privateKey); } catch (InvalidKeyException e) { throw new IllegalStateException("Private key not an ECDSA key."); } try { signature.update(payload); return signature.sign(); } catch (SignatureException e) { throw new IllegalStateException("Could not sign payload.", e); } }
ECDSA256Signer { public byte[] sign(byte[] payload) { 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.initSign(privateKey); } catch (InvalidKeyException e) { throw new IllegalStateException("Private key not an ECDSA key."); } try { signature.update(payload); return signature.sign(); } catch (SignatureException e) { throw new IllegalStateException("Could not sign payload.", e); } } }
ECDSA256Signer { public byte[] sign(byte[] payload) { 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.initSign(privateKey); } catch (InvalidKeyException e) { throw new IllegalStateException("Private key not an ECDSA key."); } try { signature.update(payload); return signature.sign(); } catch (SignatureException e) { throw new IllegalStateException("Could not sign payload.", e); } } @Inject  ECDSA256Signer(SignerConfig config); }
ECDSA256Signer { public byte[] sign(byte[] payload) { 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.initSign(privateKey); } catch (InvalidKeyException e) { throw new IllegalStateException("Private key not an ECDSA key."); } try { signature.update(payload); return signature.sign(); } catch (SignatureException e) { throw new IllegalStateException("Could not sign payload.", e); } } @Inject  ECDSA256Signer(SignerConfig config); byte[] sign(byte[] payload); }
ECDSA256Signer { public byte[] sign(byte[] payload) { 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.initSign(privateKey); } catch (InvalidKeyException e) { throw new IllegalStateException("Private key not an ECDSA key."); } try { signature.update(payload); return signature.sign(); } catch (SignatureException e) { throw new IllegalStateException("Could not sign payload.", e); } } @Inject  ECDSA256Signer(SignerConfig config); byte[] sign(byte[] payload);  }