[−][src]Struct encon::Password
Represents an encryption password, and contains the low level encrypt/decrypt operations on lists of bytes.
The encryption used is ChaCha20/Poly1305 (an Authenticated Encryption with Associated Data algorithm) of [libsodium's secret-stream].
Implementations
impl Password
[src]
pub fn new(password: impl Into<String>) -> Self
[src]
Create a new password for encryption and decryption.
pub fn encrypt(&self, bytes: impl AsRef<[u8]>) -> Result<Vec<u8>, EncryptError>
[src]
Encrypt a byte slice with this password.
Example
Note that encrypting the same data twice will give different bytes as output.
use encon::Password; let pw = Password::new("strongpassword"); let data = [0x01, 0x02, 0x03]; let first: Vec<u8> = pw.encrypt(data).unwrap(); let second: Vec<u8> = pw.encrypt(data).unwrap(); assert_ne!(first, second);
pub fn decrypt(&self, bytes: impl AsRef<[u8]>) -> Result<Vec<u8>, DecryptError>
[src]
Decrypt a byte slice with this password.
Example
Here is a known working example.
use encon::Password; let password = Password::new("strongpassword"); let buffer = password.decrypt(vec![ 0xc2, 0x0a, 0x4b, 0xed, 0x94, 0xb3, 0x10, 0xf3, 0x8e, 0x97, 0x5e, 0x9a, 0x9c, 0xb4, 0xf1, 0xd9, 0x4c, 0x32, 0xd4, 0x55, 0x60, 0x92, 0xa4, 0x40, 0x35, 0x0f, 0x21, 0x51, 0xee, 0x1b, 0x2b, 0xa2, 0x8b, 0x91, 0xdc, 0xe1, 0xc2, 0xf6, 0x47, 0x3e, 0x07, 0x1f, 0xad, 0xd2, 0x48, 0x14, 0x52, 0x85, 0xab, 0x4e, 0xa7, 0x5d, 0xee, 0xf5, 0x03, 0xb6, 0x9d, 0xcd, 0xe0, 0xe2, 0x91, 0x95, 0x49, 0x72, 0x04, 0xed, 0xb9, 0xa4, 0x9f, 0x07, 0x0b, 0x22, 0x26, 0x51, 0x62, 0x36, 0x52, ]).unwrap(); let s = String::from_utf8(buffer).unwrap(); assert_eq!(&s, "Hello, world!");
Trait Implementations
Auto Trait Implementations
impl RefUnwindSafe for Password
impl Send for Password
impl Sync for Password
impl Unpin for Password
impl UnwindSafe for Password
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
pub fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
pub fn to_owned(&self) -> T
[src]
pub fn clone_into(&self, target: &mut T)
[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,