chloride.lockbox

Members

Aliases

makeLockBoxSeed
alias makeLockBoxSeed = randomArray!LockBoxSeed

Generate a seed suitable for use with makeKeyPair

makeNonce
alias makeNonce = randomArray!Nonce

Generate a nonce suitable for encrypting a lock box.

Functions

decryptLockBox
ubyte[] decryptLockBox(in ubyte[] cipher, in Nonce nonce, in PublicKey pk, in PrivateKey sk)

Decrypt a message using a private key for the recipient (sk) and verify the signature with the public key of the sender (pk). Returns null if decryption or verification failed.

encryptLockBox
ubyte[] encryptLockBox(in ubyte[] message, in Nonce nonce, in PublicKey pk, in PrivateKey sk)

Encrypt a message using a public key for the recipient (pk) and signed with the private key of the sender sk.

lockBox
LockBox lockBox(in ubyte[] message, in PublicKey pk, in PrivateKey sk)

Encrypt and sign message using public key cryptography. The message is encrypted using the public key of the recipient (pk) and signed with the private key of the sender (sk).

makeKeyPair
KeyPair makeKeyPair()

Generate a new random key pair.

makeKeyPair
KeyPair makeKeyPair(in LockBoxSeed seed)

Generate a key pair from a seed.

openLockBox
ubyte[] openLockBox(in LockBox box, in PublicKey pk, in PrivateKey sk)

Decrypt a LockBox encrypted and signed using public key cryptography. The message is decrypted using the private key of the recipient (sk) and the signature is verified using the public key of the sender (pk). If decryption or verification fails, null is returned.

openSealedBox
ubyte[] openSealedBox(in ubyte[] cipher, in KeyPair keys)

Decrypt a sealed box using the recipient's key pair. If decryption fails, return null.

sealBox
ubyte[] sealBox(in ubyte[] message, in PublicKey pk)

Anonymously encrypt a message using the recipients public key. A new key pair is generated for each invocation, so a nonce isn't needed.

Structs

KeyPair
struct KeyPair

Struct containing a key pair for public key encryption

LockBox
struct LockBox

Struct containing a message encrypted and signed using public key cryptography. Includes the ciphertext and the nonce used to encrypt it.

Examples

1 import std.string : representation;
2 immutable ubyte[] message = representation("hello");
3 auto alice = makeKeyPair();
4 auto bob = makeKeyPair();
5 auto box = lockBox(message, bob.publicKey, alice.privateKey);
6 assert(openLockBox(box, alice.publicKey, bob.privateKey) == message);
1 import std.string : representation;
2 immutable ubyte[] message = representation("hello");
3 auto keys = makeKeyPair();
4 auto box = sealBox(message, keys.publicKey);
5 assert(openSealedBox(box, keys) == message);

Meta