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]

Creates by type

Trait Implementations

impl Send for OpenSSLCipher
[src]

impl StreamCipher for OpenSSLCipher
[src]