Bruce
  • Welcome
  • Essentials
    • Features
    • Getting Started
    • General Concepts
    • Roadmap
  • API
    • Cheat Sheet
    • Key Stores
    • Certificates
    • Keys
    • Digests
    • Signatures
    • Verification
    • Symmetric Ciphers
    • Asymmetric Ciphers
    • Message Authentication Codes
Powered by GitBook
On this page
  • Verifier
  • Usage Example
  • Verifier by Key
  • Usage Example
  • Encoding Verifier
  • Usage Example
  • Encoding Verifier with Custom Character Set
  • Usage Example

Was this helpful?

Export as PDF
  1. API

Verification

Verifier

Verifier verifier(PublicKey publicKey, String algorithm);

Returns a verifier for the given private key and algorithm.

Usage Example

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

Verifier by Key

VerifierByKey verifier(Map<String, PublicKey> publicKeyMap, String algorithm)

Returns a verifier that allows choosing the public key at runtime from a map of preconfigured keys.

Usage Example

KeyStore keystore = keystore("classpath:keystore.p12", "password".toCharArray(), "PKCS12");

PublicKey aKey = publicKey(keystore, "alice");
PublicKey bKey = publicKey(keystore, "bob");

Map<String, PublicKey> keys = Map.of("alice", aKey, "bob", bKey);

VerifierByKey verifier = verifier(keys, "SHA512withRSA");

byte[] aSignature = ...; // Alice's signature
byte[] bSignature = ...; // Bob's signature

boolean verified = verifier.verify("alice", "Hello Alice".getBytes(UTF_8), bSignature);
boolean verified = verifier.verify("bob", "Hello Bob".getBytes(UTF_8), aSignature);

Encoding Verifier

EncodingVerifier verifier(
    PublicKey publicKey, 
    String algorithm, 
    Encoding encoding
);

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

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

Encoding Verifier with Custom Character Set

EncodingVerifier verifier(
    PublicKey publicKey, 
    String algorithm, 
    Charset charset, 
    Encoding encoding
);

Usage Example

KeyStore keystore = keystore("classpath:keystore.p12", "password".toCharArray(), "PKCS12");
PublicKey publicKey = publicKey(keystore, "alice");
EncodingVerifier verifier = verifier(publicKey, "SHA512withRSA", ISO_8859_1, BASE64);
String signature = ...; // base64 encoded signature
boolean verified = verifier.verify("Hello", signature);
PreviousSignaturesNextSymmetric Ciphers

Last updated 3 years ago

Was this helpful?

Same as but allows specifying a custom character set for the plaintext messages.

encoding verifier