Bruce
Search…
Signatures

Signer

1
Signer signer(PrivateKey privateKey, String algorithm);
Copied!
Returns a signer for the given private key and algorithm.

Usage Example

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

Signer by Key

1
SignerByKey signer(Map<String, PrivateKey> privateKeyMap, String algorithm)
Copied!
Returns a signer that allows choosing the private key at runtime from a map of preconfigured keys.

Usage Example

1
KeyStore keystore = keystore("classpath:keystore.p12", "password".toCharArray(), "PKCS12");
2
3
PrivateKey aKey = privateKey(keystore, "alice", "password".toCharArray());
4
PrivateKey bKey = privateKey(keystore, "bob", "password".toCharArray());
5
6
Map<String, PrivateKey> keys = Map.of("alice", aKey, "bob", bKey);
7
8
SignerByKey signer = signer(keys, "SHA512withRSA");
9
10
byte[] aSignature = signer.sign("alice", "Hello Bob".getBytes(UTF_8));
11
byte[] bSignature = signer.sign("bob", "Hello Alice".getBytes(UTF_8));
Copied!

Encoding Signer

1
EncodingSigner signer(
2
PrivateKey privateKey,
3
String algorithm,
4
Encoding encoding
5
);
Copied!
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

1
KeyStore keystore = keystore("classpath:keystore.p12", "password".toCharArray(), "PKCS12");
2
PrivateKey privateKey = privateKey(keystore, "alice", "password".toCharArray());
3
EncodingSigner signer = signer(privateKey, "SHA512withRSA", BASE64);
4
String signature = signer.sign("Hello");
Copied!

Encoding Signer with Custom Character Set

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

Usage Example

1
KeyStore keystore = keystore("classpath:keystore.p12", "password".toCharArray(), "PKCS12");
2
PrivateKey privateKey = privateKey(keystore, "alice", "password".toCharArray());
3
EncodingSigner signer = signer(privateKey, "SHA512withRSA", ISO_8859_1, BASE64);
4
String signature = signer.sign("Hello");
Copied!
Last modified 4mo ago