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
  • Signer
  • Usage Example
  • Signer by Key
  • Usage Example
  • Encoding Signer
  • Usage Example
  • Encoding Signer with Custom Character Set
  • Usage Example

Was this helpful?

Export as PDF
  1. API

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

EncodingSigner signer(
    PrivateKey privateKey, 
    String algorithm, 
    Encoding encoding
);

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

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

Encoding Signer with Custom Character Set

EncodingSigner signer(
    PrivateKey privateKey, 
    String algorithm, 
    Charset charset, 
    Encoding encoding
);

Usage Example

KeyStore keystore = keystore("classpath:keystore.p12", "password".toCharArray(), "PKCS12");
PrivateKey privateKey = privateKey(keystore, "alice", "password".toCharArray());
EncodingSigner signer = signer(privateKey, "SHA512withRSA", ISO_8859_1, BASE64);
String signature = signer.sign("Hello");

PreviousDigestsNextVerification

Last updated 3 years ago

Was this helpful?

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

encoding signer