Skip to main content

seal

Function seal 

Source
pub fn seal<T, K>(
    value: &T,
    key: Option<K>,
) -> Result<Vec<u8>, SerializationError>
where T: Encode, K: AsRef<str>,
Expand description

Encode value to an authenticated, encrypted byte blob sealed with key.

Encryption uses ChaCha20-Poly1305 (IETF) with a freshly generated 12-byte random nonce prepended to the output. Every call produces a different ciphertext even for the same plaintext and key.

If key is None the default key "serialization/deserialization" is used. String literals (Some("key")) and owned Strings are both accepted. The resulting blob can only be decoded by open with the same key.

§Errors

Returns SerializationError::Encode if bincode cannot serialise the value.