[][src]Function private_box::encrypt

pub fn encrypt(plaintext: &[u8], recipients: &[PublicKey]) -> Vec<u8>

Takes the message you want to encrypt, and an array of recipient public keys. Returns a message that is encrypted to all recipients and openable by them with private_box::decrypt. The number of recipients must be between 1 and 32.

The encrypted length will be 56 + (recipients.len() * 33) + plaintext.len().

Example

use private_box::{encrypt, decrypt};
use ssb_crypto::Keypair;

fn main() {
    let msg = "hello!".as_bytes();

    let alice = Keypair::generate();
    let bob = Keypair::generate();

    let recps = [alice.public, bob.public];
    let cypher = encrypt(msg, &recps);

    let alice_result = decrypt(&cypher, &alice);
    let bob_result = decrypt(&cypher, &bob);

    assert_eq!(alice_result.unwrap(), msg);
    assert_eq!(bob_result.unwrap(), msg);
}