Keys

All methods below are available as static imports from com.mirkocaserta.bruce.Keystores.

Public Key

PublicKey publicKey(KeyStore keystore, String alias);

Loads a public key from a key store.

Usage Example

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

PublicKey publicKey = publicKey(keystore, "alice");

Private Key

PrivateKey privateKey(KeyStore keystore, String alias, char[] password);
PrivateKey privateKey(KeyStore keystore, String alias, String password);

Loads a private key from a key store. The password parameter is the private key's password.

Usage Example

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

PrivateKey privateKey = privateKey(keystore, "alice", "password".toCharArray());
// or with String convenience overload:
PrivateKey privateKey = privateKey(keystore, "alice", "password");

Secret Key

Loads a secret key from a key store. The password parameter is the secret key's password.

Usage Example

Symmetric Key

Generates a random symmetric key using the given algorithm.

Usage Examples

Key Pair

Generates a pair of keys for asymmetric cryptography.

Usage Example

Key Pair with Custom PRNG

Same as key pair but allows passing a SecureRandom instance for custom initialization of the pseudo random number generator.

Usage Example

Last updated

Was this helpful?