Bruce
Search…
Keys

Public Key

1
PublicKey publicKey(
2
KeyStore keystore,
3
String alias
4
);
Copied!
Loads a public key from a key store.

Usage Example

1
KeyStore keystore = keystore(
2
"classpath:keystore.p12",
3
"password".toCharArray(),
4
"PKCS12"
5
);
6
7
PublicKey publicKey = publicKey(keystore, "alice");
Copied!

Private Key

1
PrivateKey privateKey(
2
KeyStore keystore,
3
String alias,
4
char[] password
5
);
Copied!
Loads a public key from a key store. The password parameter is the private key's password.

Usage Example

1
KeyStore keystore = keystore(
2
"classpath:keystore.p12",
3
"password".toCharArray(),
4
"PKCS12"
5
);
6
7
PrivateKey privateKey =
8
privateKey(keystore, "alice", "password".toCharArray());
Copied!

Secret Key

1
Key secretKey(
2
KeyStore keystore,
3
String alias,
4
char[] password
5
);
Copied!
Loads a secret key from a key store. The password parameter is the secret key's password.

Usage Example

1
KeyStore keystore = keystore(
2
"classpath:/keystore.p12",
3
"password".toCharArray(),
4
"PKCS12"
5
);
6
7
Key key = secretKey(keystore, "alice", "password".toCharArray());
Copied!

Symmetric Key

1
byte[] symmetricKey(String algorithm);
Copied!
Generates a symmetric key using the given algorithm.

Usage Example

1
byte[] key = symmetricKey("DESede");
Copied!

Encoded Symmetric Key

1
String symmetricKey(String algorithm, Encoding encoding);
Copied!
Generates a symmetric key using the given algorithm and encoding.

Usage Example

1
String key = symmetricKey("DESede", BASE64);
Copied!

Key Pair

1
KeyPair keyPair(String algorithm, int keySize);
Copied!
Generates a pair of keys for asymmetric cryptography.

Usage Example

1
KeyPair keyPair = keyPair("RSA", 4096);
2
Signer signer = signer(keyPair.getPrivate(), "SHA512withRSA");
3
Verifier verifier = verifier(keyPair.getPublic(), "SHA512withRSA");
4
byte[] signature = signer.sign(MESSAGE);
5
assertTrue(verifier.verify(MESSAGE, signature));
Copied!

Key Pair with Custom PRNG

1
KeyPair keyPair(
2
String algorithm,
3
int keySize,
4
SecureRandom random
5
);
Copied!
Same as key pair but allows passing a SecureRandom instance for custom initialization of the pseudo random number generator used when generating the keys.

Usage Example

1
SecureRandom random = SecureRandom.getInstanceStrong();
2
random.setSeed(new byte[]{0, 1, 2, 3, 4, 5});
3
KeyPair keyPair = keyPair("RSA", 4096, random);
4
Signer signer = signer(keyPair.getPrivate(), "SHA512withRSA");
5
Verifier verifier = verifier(keyPair.getPublic(), "SHA512withRSA");
6
byte[] signature = signer.sign(MESSAGE);
7
assertTrue(verifier.verify(MESSAGE, signature));
Copied!
Last modified 4mo ago