[]Struct themis::secure_message::SecureMessage

pub struct SecureMessage { /* fields omitted */ }

Secure Message encryption and decryption.

Encrypted message is useful when you need the full stack of protection for your data — in most cases you will be using this flavor. Encrypted messages currently use Secure Cell in sealing mode for data protection.

Examples

In order to use Secure Message in encrypting mode you will need to have both public and private keys available on both peers. Typical usage of Secure Message looks like this:

use themis::secure_message::SecureMessage;
use themis::keygen::gen_ec_key_pair;

// Generate and share this key pair between peers.
let key_pair = gen_ec_key_pair();

// Alice uses her own Secure Message instance to encrypt messages.
let secure_a = SecureMessage::new(key_pair.clone());
let encrypted = secure_a.encrypt(b"message")?;

// Bob uses his Secure Message instance to decrypt received messages.
let secure_b = SecureMessage::new(key_pair.clone());
let decrypted = secure_b.decrypt(&encrypted)?;

assert_eq!(decrypted, b"message");

Methods

impl SecureMessage

pub fn new(key_pair: impl Into<KeyPair>) -> Self

Makes a new Secure Message using given key pair.

Both ECDSA and RSA key pairs are supported.

pub fn encrypt(&self, message: impl AsRef<[u8]>) -> Result<Vec<u8>>

Encrypts the provided message into a secure container.

Examples

You can use anything convertible into a byte slice as a message: a byte slice or an array, a Vec<u8>, or a String.

use themis::secure_message::SecureMessage;
use themis::keygen::gen_ec_key_pair;

let secure = SecureMessage::new(gen_ec_key_pair());

secure.encrypt(b"byte string")?;
secure.encrypt(&[1, 2, 3, 4, 5])?;
secure.encrypt(vec![6, 7, 8, 9])?;
secure.encrypt(format!("owned string"))?;

pub fn decrypt(&self, message: impl AsRef<[u8]>) -> Result<Vec<u8>>

Decrypts an encrypted message back into its original form.

Trait Implementations

impl Debug for SecureMessage

Auto Trait Implementations

Blanket Implementations

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> From<T> for T[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> Any for T where
    T: 'static + ?Sized
[src]