pub fn unseal(algorithm: EncryptionAlg, secret_key: &[u8], ciphertext: &[u8]) -> Result<Vec<u8>> {
    // AES256GCM is the only encryption algorithm we presently support
    assert_eq!(algorithm, EncryptionAlg::AES256GCM);

    // The ciphertext must start with a valid nonce
    if ciphertext.len() < AES256GCM_NONCE_SIZE {
        return Err(
            ErrorKind::CryptoFailure("nonce missing from ciphertext".to_string()).into(),
        );
    }

    let opening_key = aead::OpeningKey::new(&aead::AES_256_GCM, secret_key)
        .chain_err(|| "encryption key is corrupt")?;

    // Extract nonce from beginning of plaintext
    let nonce = &ciphertext[0..AES256GCM_NONCE_SIZE];
    let mut buffer = Vec::from(&ciphertext[AES256GCM_NONCE_SIZE..]);

    let pt_len = aead::open_in_place(&opening_key, nonce, &b""[..], 0, &mut buffer)
        .chain_err(|| "decryption failed")?
        .len();

    buffer.truncate(pt_len);
    Ok(buffer)
}
/// Decrypt the given ciphertext using the given algorithm
Decrypt the given ciphertext using the given algorithm
Decrypt the given ciphertext using the given algorithm
pub fn unseal(algorithm: EncryptionAlg, secret_key: &[u8], ciphertext: &[u8]) -> Result<Vec<u8>> {
    // AES256GCM is the only encryption algorithm we presently support
    assert_eq!(algorithm, EncryptionAlg::AES256GCM);
    // The ciphertext must start with a valid nonce
    if ciphertext.len() < AES256GCM_NONCE_SIZE {
        return Err(
            ErrorKind::CryptoFailure("nonce missing from ciphertext".to_string()).into(),
        );
    }
    let opening_key = aead::OpeningKey::new(&aead::AES_256_GCM, secret_key)
        .chain_err(|| "encryption key is corrupt")?;
    // Extract nonce from beginning of plaintext
    let nonce = &ciphertext[0..AES256GCM_NONCE_SIZE];
    let mut buffer = Vec::from(&ciphertext[AES256GCM_NONCE_SIZE..]);
    let pt_len = aead::open_in_place(&opening_key, nonce, &b""[..], 0, &mut buffer)
        .chain_err(|| "decryption failed")?
        .len();
    buffer.truncate(pt_len);
    Ok(buffer)
}
pub fn unseal ( algorithm : EncryptionAlg , secret_key : & [ u8 ] , ciphertext : & [ u8 ] ) -> Result < Vec < u8 > > { // AES256GCM is the only encryption algorithm we presently support assert_eq ! ( algorithm EncryptionAlg AES256GCM ) ; // The ciphertext must start with a valid nonce if ciphertext . len ( ) < AES256GCM_NONCE_SIZE { return Err ( ErrorKind :: CryptoFailure ( " " . to_string ( ) ) . into ( ) , ) ; } let opening_key = aead :: OpeningKey :: new ( & aead :: AES_256_GCM , secret_key ) . chain_err ( | | " " ) ? ; // Extract nonce from beginning of plaintext let nonce = & ciphertext [ 0 .. AES256GCM_NONCE_SIZE ] ; let mut buffer = Vec :: from ( & ciphertext [ AES256GCM_NONCE_SIZE .. ] ) ; let pt_len = aead :: open_in_place ( & opening_key , nonce , & b" " [ .. ] , 0 , & mut buffer ) . chain_err ( | | " " ) ? . len ( ) ; buffer . truncate ( pt_len ) ; Ok ( buffer ) }
Decrypt the given ciphertext using the given algorithm
Decrypt the given ciphertext using the given algorithm
algorithm
EncryptionAlg
secret_key
&[u8]
ciphertext
&[u8]
algorithm
EncryptionAlg
secret_key
&[u8]
ciphertext
&[u8]