Function private_box::decrypt [−][src]
pub fn decrypt(cyphertext: &[u8], secret_key: &SecretKey) -> Result<Vec<u8>, ()>
Attempt to decrypt a private-box message, using your secret key. If you were an intended recipient then the decrypted message is returned as Ok(Vec<u8>)
. If it was not for you, then Err(())
will be returned.
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); }