Struct shadowsocks::crypto::openssl::OpenSSLCipher
[−]
[src]
pub struct OpenSSLCipher { /* fields omitted */ }The Cipher binding for OpenSSL's libcrypto.
It should be noticed that the decipher needs to read the iv (initialization vector)
from the first call of decrypt. So the cipher will have to insert the iv into
the front of the encrypted data.
Note: This behavior works just the same as the official version of shadowsocks.
use shadowsocks::crypto::{CryptoMode, StreamCipher, CipherType}; use shadowsocks::crypto::openssl::OpenSSLCipher; let method = CipherType::Aes128Cfb; let key = method.bytes_to_key(b"password"); let iv = method.gen_init_vec(); let mut enc = OpenSSLCipher::new(method, &key[0..], &iv[0..], CryptoMode::Encrypt); let mut dec = OpenSSLCipher::new(method, &key[0..], &iv[0..], CryptoMode::Decrypt); let message = "hello world"; let mut encrypted_message = Vec::new(); enc.update(message.as_bytes(), &mut encrypted_message).unwrap(); let mut decrypted_message = Vec::new(); dec.update(&encrypted_message[..], &mut decrypted_message).unwrap(); assert!(&decrypted_message[..] == message.as_bytes());
Methods
impl OpenSSLCipher[src]
fn new(
cipher_type: CipherType,
key: &[u8],
iv: &[u8],
mode: CryptoMode
) -> OpenSSLCipher
cipher_type: CipherType,
key: &[u8],
iv: &[u8],
mode: CryptoMode
) -> OpenSSLCipher
Creates by type