pub fn decrypt<M: AsRef<[u8]>, T: AsRef<[u8]>>(&self, message: M, token: T) -> Result<Vec<u8>> {
        decrypt_token_protect(
            self.0.master_key.as_bytes(),
            self.0.user_context.as_bytes(),
            message.as_ref(),
            token.as_ref(),
        )
    }
/// Extracts the original message from encrypted container and validates its authenticity.
///
/// You need to provide both the encrypted container and the authentication token previously
/// obtained from `encrypt()`. Decryption will fail if any of them is corrupted or invalid.
///
/// # Examples
///
/// If you know the master key, the context, and the token then getting back your data is easy:
///
/// ```
/// # fn main() -> Result<(), themis::Error> {
/// use themis::secure_cell::SecureCell;
///
/// let cell = SecureCell::with_key(b"password").token_protect();
///
/// let (encrypted, token) = cell.encrypt(b"byte string")?;
/// let decrypted = cell.decrypt(&encrypted, &token)?;
/// assert_eq!(decrypted, b"byte string");
/// # Ok(())
/// # }
/// ```
///
/// However, you obviously cannot use tokens produced by Secure Cells with different keys:
///
/// ```
/// # use themis::secure_cell::SecureCell;
/// #
/// # let cell = SecureCell::with_key(b"password").token_protect();
/// # let (encrypted, token) = cell.encrypt(b"byte string").unwrap();
/// #
/// let different_cell = SecureCell::with_key(b"qwerty123").token_protect();
///
/// assert!(different_cell.decrypt(&encrypted, &token).is_err());
/// ```
///
/// Or by the same Secure Cell for different data:
///
/// ```
/// # fn main() -> Result<(), themis::Error> {
/// # use themis::secure_cell::SecureCell;
/// #
/// # let cell = SecureCell::with_key(b"password").token_protect();
/// #
/// let (encrypted,   _) = cell.encrypt(b"byte string")?;
/// let (_, other_token) = cell.encrypt(b"other data")?;
///
/// assert!(cell.decrypt(&encrypted, &other_token).is_err());
/// # Ok(())
/// # }
/// ```
///
/// Secure Cell in token protect mode checks data integrity and can see if the data (or the
/// token) was corrupted, returning an error on decryption attempts:
///
/// ```
/// # use themis::secure_cell::SecureCell;
/// #
/// # let cell = SecureCell::with_key(b"password").token_protect();
/// # let (encrypted, auth_token) = cell.encrypt(b"byte string").unwrap();
/// #
/// // Let's flip some bits somewhere.
/// let mut corrupted_data = encrypted.clone();
/// let mut corrupted_token = auth_token.clone();
/// corrupted_data[10] = !corrupted_data[10];
/// corrupted_token[9] = !corrupted_token[9];
///
/// assert!(cell.decrypt(&corrupted_data, &auth_token).is_err());
/// assert!(cell.decrypt(&encrypted, &corrupted_token).is_err());
/// ```
Extracts the original message from encrypted container and validates its authenticity.
You need to provide both the encrypted container and the authentication token previously
obtained from `encrypt()`. Decryption will fail if any of them is corrupted or invalid.
Extracts the original message from encrypted container and validates its authenticity . You need to provide both the encrypted container and the authentication token previously obtained from ` encrypt () ` . Decryption will fail if any of them is corrupted or invalid .
pub fn decrypt<M: AsRef<[u8]>, T: AsRef<[u8]>>(&self, message: M, token: T) -> Result<Vec<u8>> {
        decrypt_token_protect(
            self.0.master_key.as_bytes(),
            self.0.user_context.as_bytes(),
            message.as_ref(),
            token.as_ref(),
        )
    }
pub fn decrypt < M : AsRef < [ u8 ] > , T : AsRef < [ u8 ] > > ( & self , message : M , token : T ) -> Result < Vec < u8 > > { decrypt_token_protect ( self . 0 . master_key . as_bytes ( ) , self . 0 . user_context . as_bytes ( ) , message . as_ref ( ) , token . as_ref ( ) , ) }
Extracts the original message from encrypted container and validates its authenticity.
Extracts the original message from encrypted container and validates its authenticity .
&self
message
M
token
T
&self
message
M
token
T
examples
If you know the master key, the context, and the token then getting back your data is easy.


If you know the master key the context and the token then getting back your data is easy .
fn main() -> result<(), themis::error> {
use themis::secure_cell::SecureCell.

let cell = SecureCell::with_key(b"password").token_protect().

let (encrypted, token) = cell.encrypt(b"byte string")?;
let decrypted = cell.decrypt(&encrypted, &token)?;
assert_eq!(decrypted, b"byte string").
use themis :: secure_cell :: SecureCell . let cell = SecureCell :: with_key ( b " password " ) . token_protect () . let ( encrypted token ) = cell . encrypt ( b " byte string " ) ? ; let decrypted = cell . decrypt ( &encrypted &token ) ? ; assert_eq! ( decrypted b " byte string " ) .
ok(())
None
}


However, you obviously cannot use tokens produced by Secure Cells with different keys.


However you obviously cannot use tokens produced by Secure Cells with different keys .
use themis::secure_cell::securecell;
None
let cell = securecell::with_key(b"password").token_protect();
None
let (encrypted, token) = cell.encrypt(b"byte string").unwrap();
let different_cell = SecureCell::with_key(b"qwerty123").token_protect().

assert!(different_cell.decrypt(&encrypted, &token).is_err());
```

Or by the same Secure Cell for different data.


let different_cell = SecureCell :: with_key ( b " qwerty123 " ) . token_protect () . assert! ( different_cell . decrypt ( &encrypted &token ) . is_err () ) ; ` ` ` Or by the same Secure Cell for different data .
fn main() -> result<(), themis::error> {
None
use themis::secure_cell::securecell;
None
let cell = securecell::with_key(b"password").token_protect();
let (encrypted,   _) = cell.encrypt(b"byte string")?;
let (_, other_token) = cell.encrypt(b"other data")?.

assert!(cell.decrypt(&encrypted, &other_token).is_err()).
let ( encrypted _ ) = cell . encrypt ( b " byte string " ) ? ; let ( _ other_token ) = cell . encrypt ( b " other data " ) ? . assert! ( cell . decrypt ( &encrypted &other_token ) . is_err () ) .
ok(())
None
}


Secure Cell in token protect mode checks data integrity and can see if the data (or the
token) was corrupted, returning an error on decryption attempts.


Secure Cell in token protect mode checks data integrity and can see if the data ( or the token ) was corrupted returning an error on decryption attempts .
use themis::secure_cell::securecell;
None
let cell = securecell::with_key(b"password").token_protect();
None
let (encrypted, auth_token) = cell.encrypt(b"byte string").unwrap();
Let's flip some bits somewhere.
let mut corrupted_data = encrypted.clone();
let mut corrupted_token = auth_token.clone();
corrupted_data[10] = !corrupted_data[10];
corrupted_token[9] = !corrupted_token[9].

assert!(cell.decrypt(&corrupted_data, &auth_token).is_err());
assert!(cell.decrypt(&encrypted, &corrupted_token).is_err());
```
Let ' s flip some bits somewhere . let mut corrupted_data = encrypted . clone () ; let mut corrupted_token = auth_token . clone () ; corrupted_data [ 10 ] = !corrupted_data [ 10 ] ; corrupted_token [ 9 ] = !corrupted_token [ 9 ] . assert! ( cell . decrypt ( &corrupted_data &auth_token ) . is_err () ) ; assert! ( cell . decrypt ( &encrypted &corrupted_token ) . is_err () ) ; ` ` `