Asymmetric Ciphers
Cipher
Cipher cipher(Key key, String algorithm, Mode mode);�Returns an asymmetric cipher.
Usage Example
KeyStore aliceKeystore = keystore("classpath:/keystore-alice.p12", "password", "PKCS12");
KeyStore bobKeystore = keystore("classpath:/keystore-bob.p12", "password", "PKCS12");
Key alicePrivateKey = privateKey(aliceKeystore, "alice", "password");
Key bobPrivateKey = privateKey(bobKeystore, "bob", "password");
Key alicePublicKey = publicKey(aliceKeystore, "alice");
Key bobPublicKey = publicKey(bobKeystore, "bob");
Cipher encryptForAlice = cipher(alicePublicKey, "RSA", ENCRYPT);
Cipher decryptForAlice = cipher(alicePrivateKey, "RSA", DECRYPT);
Cipher encryptForBob = cipher(bobPublicKey, "RSA", ENCRYPT);
Cipher decryptForBob = cipher(bobPrivateKey, "RSA", DECRYPT);
// Alice writes to Bob
byte[] aliceMsg01 = "Hello".getBytes(UTF_8);
byte[] aliceMsg01Encrypted = encryptForBob.encrypt(aliceMsg01);
// Bob decrypts Alice's message
byte[] aliceMsg01Decrypted = decryptForBob.encrypt(aliceMsg01Encrypted);
// Bob responds to Alice's message
byte[] bobMsg01 = "Hey Alice, nice to hear from you.".getBytes(UTF_8);
byte[] bobMsg01Encrypted = encryptForAlice.encrypt(bobMsg01);
// Alice decrypts Bob's message
byte[] bobMsg01Decrypted = decryptForAlice.encrypt(bobMsg01Encrypted);Builder Pattern Alternative
For complex asymmetric cipher configurations, use the fluent builder API:
Basic Asymmetric Cipher Builder
Advanced Asymmetric Cipher Builder
�Cipher By Key
�Returns a cipher interface for working with a map of preconfigured keys.
Usage Example
�Encoding Cipher
�Returns an encoding cipher. The character set refers to the plain text message string encoding.
Usage Example
�Encoding Cipher By Key
�Returns an encoding cipher with a set of preconfigured keys.
Usage Example
Last updated
Was this helpful?