Signatures

Signer

Signer signer(PrivateKey privateKey, String algorithm);

�Returns a signer for the given private key and algorithm.

Usage Example

KeyStore keystore = keystore("classpath:keystore.p12", "password".toCharArray(), "PKCS12");
PrivateKey privateKey = privateKey(keystore, "alice", "password".toCharArray());
Signer signer = signer(privateKey, "SHA512withRSA");
byte[] signature = signer.sign("Hello".getBytes(UTF_8));

Signer by Key

SignerByKey signer(Map<String, PrivateKey> privateKeyMap, String algorithm)

�Returns a signer that allows choosing the private key at runtime from a map of preconfigured keys.

Usage Example

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

PrivateKey aKey = privateKey(keystore, "alice", "password".toCharArray());
PrivateKey bKey = privateKey(keystore, "bob", "password".toCharArray());

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

SignerByKey signer = signer(keys, "SHA512withRSA");

byte[] aSignature = signer.sign("alice", "Hello Bob".getBytes(UTF_8));
byte[] bSignature = signer.sign("bob", "Hello Alice".getBytes(UTF_8));

Encoding Signer

�Returns an encoding signer 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

�Encoding Signer with Custom Character Set

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

Usage Example

Builder Pattern Alternative

For complex signer configurations, you can use the fluent builder API to avoid parameter overload:

Basic Signer Builder

Advanced Signer Builder

Multi-Key Signer Builder

Last updated

Was this helpful?