[−][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![ 0xc1, 0x0a, 0x4b, 0xed, 0x72, 0xa5, 0xb6, 0xec, 0xa2, 0xb2, 0x77, 0xcd, 0x5f, 0x4b, 0xa1, 0x1e, 0x70, 0x73, 0x01, 0xd3, 0xbd, 0xb0, 0x5f, 0x9f, 0xfa, 0x69, 0xfc, 0x9a, 0xf2, 0x28, 0xa7, 0x51, 0xc4, 0x70, 0xe0, 0x68, 0x2f, 0x04, 0x90, 0x1a, 0xbc, 0xfc, 0xf4, 0x79, 0x14, 0x94, 0x38, 0x1f, 0x0a, 0x36, 0xf2, 0xe1, 0x1f, 0x67, 0x87, 0x9b, 0x13, 0x01, 0xb3, 0x8b, 0x1b, 0xff, 0x41, 0xce, 0x15, 0xef, 0x13, 0xdc, 0x57, 0xf1, 0xc0, 0x65, 0x5a, 0x00, 0x3d, 0x23, 0xc8, 0x04, 0x4e, 0xe7, 0xd4, 0x29, 0x62, 0xa0, 0x85, 0x98, 0x04, 0x36, 0xea, 0xdf, ]).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>,