pub struct MessageEncryption { /* private fields */ }Expand description
A storage container that represents a message you want to encrypt/decrypt. In order for both operations to work, you also need to store the encryption key and additional authenticated data (plaintext).
§Examples
You can create a MessageEncryption using the following code:
use street_cred::MessageEncryption;
let message = b"secret message".to_vec();
let key = "425D76994EE6101105DDDA2EE2604AA0";
let aad = "additional authenticated data";
let encryptor = MessageEncryption::new(message, key, aad);Implementations§
Source§impl MessageEncryption
impl MessageEncryption
Sourcepub fn new(message: Vec<u8>, key: &str, aad: &str) -> Self
pub fn new(message: Vec<u8>, key: &str, aad: &str) -> Self
Create a new instance of MessageEncryption
§Arguments
message- Message to be encryptedkey- Key to use for encryption/decryptionaad- Additional authenticated data
§Examples
use street_cred::MessageEncryption;
let message = b"secret message".to_vec();
let key = "425D76994EE6101105DDDA2EE2604AA0";
let aad = "additional authenticated data";
let encryptor = MessageEncryption::new(message, key, aad);Sourcepub fn decrypt(&self, iv: &str, tag: &str) -> Result<String>
pub fn decrypt(&self, iv: &str, tag: &str) -> Result<String>
Decrypts the contents of the MessageEncryption and returns them as a String
§Arguments
iv- Initialization vector used when initially encrypting the messagetag- Additional Authenticated data resulting from encrypting the message
§Examples
use street_cred::MessageEncryption;
let encrypted_message = b"".to_vec();
let key = "425D76994EE6101105DDDA2EE2604AA0";
let plaintext_aad = "";
let iv = "fWoW3cyLE2/JfiiF";
let tag = "DyMEJPXzmksJGb+QumM2Rd6X";
let decryptor = MessageEncryption::new(encrypted_message, key, plaintext_aad);
let decrypted_contents = decryptor.decrypt(iv, tag);
match decrypted_contents {
Ok(contents) => println!("Decrypted Contents: {}", contents),
Err(why) => println!("Error: {}", why),
}Sourcepub fn encrypt(&self) -> Result<String>
pub fn encrypt(&self) -> Result<String>
Encrypts the contents of the MessageEncryption and returns them as a String
§Examples
use street_cred::MessageEncryption;
let plaintext_message = b"super secret message".to_vec();
let key = "16 byte key line";
let plaintext_aad = "";
let encryptor = MessageEncryption::new(plaintext_message, key, plaintext_aad);
let encrypted_contents = encryptor.encrypt();
match encrypted_contents {
Ok(contents) => println!("Encrypted Contents: {}", contents),
Err(why) => println!("Error: {}", why),
}Sourcepub fn split_encrypted_contents(contents: &str) -> Result<Vec<&str>>
pub fn split_encrypted_contents(contents: &str) -> Result<Vec<&str>>
Split contents of an encrypted file into a Vec with a length of 3. The first index is the encrypted contents, the second index is the initialization vector, and the third index is the additional authenticated data.
§Arguments
contents- The entire encrypted file as one long string. Encrypted contents should be formatted like this: “message–iv–aad”
§Examples
use street_cred::MessageEncryption;
let encrypted_contents = "HPxd1UcM3cH+Rt0HaIOFzdHqIPWIc3yR--/EoLW7ichWLzLh3V--7L1L8uPH7LoQYLkEfIckgA==";
let split_parts = MessageEncryption::split_encrypted_contents(encrypted_contents);Auto Trait Implementations§
impl Freeze for MessageEncryption
impl RefUnwindSafe for MessageEncryption
impl Send for MessageEncryption
impl Sync for MessageEncryption
impl Unpin for MessageEncryption
impl UnsafeUnpin for MessageEncryption
impl UnwindSafe for MessageEncryption
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more