Struct fernet::Fernet
[−]
[src]
pub struct Fernet { /* fields omitted */ }
Methods
impl Fernet
[src]
Fernet
encapsulates encrypt and decrypt operations for a particular key.
pub fn new(key: &str) -> Option<Fernet>
[src]
Returns a new fernet instance with the provided key. The key should be
32-bytes, base64-encoded. Generating keys with Fernet::generate_key
is recommended. DO NOT USE A HUMAN READABLE PASSWORD AS A KEY. Returns
None
if the key is not 32-bytes base64 encoded.
pub fn generate_key() -> String
[src]
Generates a new, random, key. Can be safely passed to Fernet::new()
.
Store this somewhere safe!
pub fn encrypt(&self, data: &[u8]) -> String
[src]
Encrypts data. Returns a value (which is base64-encoded) that can be
passed to Fernet::decrypt
.
pub fn decrypt(&self, token: &str) -> Result<Vec<u8>, DecryptionError>
[src]
Decrypts a ciphertext. Returns either Ok(plaintext)
if decryption is
successful or Err(DecryptionError)
if there are any errors.