Function private_box::encrypt [] [src]

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 7.

The encrypted length will be 56 + (recipients.length * 33) + plaintext.length bytes long, between 89 and 287 bytes longer than the plaintext.

Example

extern crate private_box;
extern crate sodiumoxide;

use private_box::{init, encrypt, decrypt};
use sodiumoxide::crypto::box_::curve25519xsalsa20poly1305::gen_keypair;
fn main() {
    let msg : [u8; 3] = [0,1,2];

    init();
    let (alice_pk, alice_sk) = gen_keypair();
    let (bob_pk, bob_sk) = gen_keypair();

    let recps = [alice_pk, bob_pk];
    let cypher = encrypt(&msg, &recps);

    let alice_result = decrypt(&cypher, &alice_sk);
    let bob_result = decrypt(&cypher, &bob_sk);

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