Bruce
Search…
Verification

Verifier

1
Verifier verifier(PublicKey publicKey, String algorithm);
Copied!
Returns a verifier for the given private key and algorithm.

Usage Example

1
KeyStore keystore = keystore("classpath:keystore.p12", "password".toCharArray(), "PKCS12");
2
PublicKey publicKey = publicKey(keystore, "alice");
3
Verifier verifier = verifier(publicKey, "SHA512withRSA");
4
byte[] signature = ...;
5
boolean verified = verifier.verify("Hello".getBytes(UTF_8), signature);
Copied!

Verifier by Key

1
VerifierByKey verifier(Map<String, PublicKey> publicKeyMap, String algorithm)
Copied!
Returns a verifier that allows choosing the public key at runtime from a map of preconfigured keys.

Usage Example

1
KeyStore keystore = keystore("classpath:keystore.p12", "password".toCharArray(), "PKCS12");
2
3
PublicKey aKey = publicKey(keystore, "alice");
4
PublicKey bKey = publicKey(keystore, "bob");
5
6
Map<String, PublicKey> keys = Map.of("alice", aKey, "bob", bKey);
7
8
VerifierByKey verifier = verifier(keys, "SHA512withRSA");
9
10
byte[] aSignature = ...; // Alice's signature
11
byte[] bSignature = ...; // Bob's signature
12
13
boolean verified = verifier.verify("alice", "Hello Alice".getBytes(UTF_8), bSignature);
14
boolean verified = verifier.verify("bob", "Hello Bob".getBytes(UTF_8), aSignature);
Copied!

Encoding Verifier

1
EncodingVerifier verifier(
2
PublicKey publicKey,
3
String algorithm,
4
Encoding encoding
5
);
Copied!
Returns an encoding verifier for the given key, algorithm and encoding. Assumes using the default JCA provider and UTF-8 as the plaintext string character set encoding.

Usage Example

1
KeyStore keystore = keystore("classpath:keystore.p12", "password".toCharArray(), "PKCS12");
2
PublicKey publicKey = publicKey(keystore, "alice");
3
EncodingVerifier verifier = verifier(publicKey, "SHA512withRSA", BASE64);
4
String signature = ...; // base64 encoded signature
5
boolean verified = verifier.verify("Hello", signature);
Copied!

Encoding Verifier with Custom Character Set

1
EncodingVerifier verifier(
2
PublicKey publicKey,
3
String algorithm,
4
Charset charset,
5
Encoding encoding
6
);
Copied!
Same as encoding verifier but allows specifying a custom character set for the plaintext messages.

Usage Example

1
KeyStore keystore = keystore("classpath:keystore.p12", "password".toCharArray(), "PKCS12");
2
PublicKey publicKey = publicKey(keystore, "alice");
3
EncodingVerifier verifier = verifier(publicKey, "SHA512withRSA", ISO_8859_1, BASE64);
4
String signature = ...; // base64 encoded signature
5
boolean verified = verifier.verify("Hello", signature);
Copied!
Last modified 6mo ago