Struct safe_crypto::SymmetricKey [−][src]
pub struct SymmetricKey { /* fields omitted */ }
Secret key for authenticated symmetric encryption.
Methods
impl SymmetricKey
[src]
impl SymmetricKey
pub fn new() -> Self
[src]
pub fn new() -> Self
Generates a new symmetric key.
pub fn from_bytes(key: [u8; 32]) -> Self
[src]
pub fn from_bytes(key: [u8; 32]) -> Self
Create a symmetric key from bytes. Useful when it has been serialised.
pub fn into_bytes(self) -> [u8; 32]
[src]
pub fn into_bytes(self) -> [u8; 32]
Convert the SharedSecretKey
into the raw underlying bytes.
For anyone who wants to store the symmetric key
pub fn encrypt<T: Serialize>(&self, plaintext: &T) -> Result<Vec<u8>, Error>
[src]
pub fn encrypt<T: Serialize>(&self, plaintext: &T) -> Result<Vec<u8>, Error>
Encrypts serialisable plaintext
using authenticated symmetric encryption.
With authenticated encryption the recipient will be able to confirm that the message
is untampered with.
If you wish to encrypt bytestring plaintext, use encrypt_bytes
.
Returns ciphertext in case of success.
Can return an Error
in case of a serialisation error.
pub fn encrypt_with_nonce<T: Serialize>(
&self,
plaintext: &T,
nonce: &Nonce
) -> Result<Vec<u8>, Error>
[src]
pub fn encrypt_with_nonce<T: Serialize>(
&self,
plaintext: &T,
nonce: &Nonce
) -> Result<Vec<u8>, Error>
Encrypts serialisable plaintext
using authenticated symmetric encryption, with a nonce.
See encrypt
.
pub fn encrypt_bytes_with_nonce(
&self,
plaintext: &[u8],
nonce: &Nonce
) -> Result<Vec<u8>, Error>
[src]
pub fn encrypt_bytes_with_nonce(
&self,
plaintext: &[u8],
nonce: &Nonce
) -> Result<Vec<u8>, Error>
Encrypts bytestring plaintext
using authenticated symmetric encryption, with a nonce.
See encrypt_bytes
.
pub fn encrypt_bytes(&self, plaintext: &[u8]) -> Result<Vec<u8>, Error>
[src]
pub fn encrypt_bytes(&self, plaintext: &[u8]) -> Result<Vec<u8>, Error>
Encrypts bytestring plaintext
using authenticated symmetric encryption.
With authenticated encryption the recipient will be able to confirm that the message is untampered with.
Returns ciphertext in case of success.
Can return an Error
in case of a serialisation error.
pub fn decrypt<T>(&self, ciphertext: &[u8]) -> Result<T, Error> where
T: DeserializeOwned + Serialize,
[src]
pub fn decrypt<T>(&self, ciphertext: &[u8]) -> Result<T, Error> where
T: DeserializeOwned + Serialize,
Decrypts serialised ciphertext
encrypted using authenticated symmetric encryption.
With authenticated encryption we will be able to tell that the message hasn't been tampered with.
Returns deserialised type T
in case of success.
Can return Error
in case of a deserialisation error, if the ciphertext
is not valid, or if it can not be decrypted.
pub fn decrypt_bytes(&self, ciphertext: &[u8]) -> Result<Vec<u8>, Error>
[src]
pub fn decrypt_bytes(&self, ciphertext: &[u8]) -> Result<Vec<u8>, Error>
Decrypts bytestring ciphertext
encrypted using authenticated symmetric encryption.
With authenticated encryption we will be able to tell that the message hasn't been tampered with.
Returns plaintext in case of success.
Can return Error
in case of a deserialisation error, if the ciphertext
is not valid, or if it can not be decrypted.
Trait Implementations
impl Debug for SymmetricKey
[src]
impl Debug for SymmetricKey
fn fmt(&self, f: &mut Formatter) -> Result
[src]
fn fmt(&self, f: &mut Formatter) -> Result
Formats the value using the given formatter. Read more
impl PartialEq for SymmetricKey
[src]
impl PartialEq for SymmetricKey
fn eq(&self, other: &SymmetricKey) -> bool
[src]
fn eq(&self, other: &SymmetricKey) -> bool
This method tests for self
and other
values to be equal, and is used by ==
. Read more
fn ne(&self, other: &SymmetricKey) -> bool
[src]
fn ne(&self, other: &SymmetricKey) -> bool
This method tests for !=
.
impl Eq for SymmetricKey
[src]
impl Eq for SymmetricKey
impl Clone for SymmetricKey
[src]
impl Clone for SymmetricKey
fn clone(&self) -> SymmetricKey
[src]
fn clone(&self) -> SymmetricKey
Returns a copy of the value. Read more
fn clone_from(&mut self, source: &Self)
1.0.0[src]
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from source
. Read more
impl Default for SymmetricKey
[src]
impl Default for SymmetricKey
Auto Trait Implementations
impl Send for SymmetricKey
impl Send for SymmetricKey
impl Sync for SymmetricKey
impl Sync for SymmetricKey