\r
fn decode_key(key: &str) -> Result<Vec<u8>, KeyError> {\r
match base64::decode(key) {\r
\r
fn decode_key(key: &str) -> Result<Vec<u8>, KeyError> {\r
match base64::decode(key) {\r
/// IV: 16 bytes randomized.\r
/// Mode : CBC.\r
pub fn encrypt(key: &str, plain_text: &str) -> Result<String, EncryptError> {\r
/// IV: 16 bytes randomized.\r
/// Mode : CBC.\r
pub fn encrypt(key: &str, plain_text: &str) -> Result<String, EncryptError> {\r
/// Decrypt the given text with the given key. The key length must be 128 bits encoded in base64.\r
/// Input format: "1" + base_64(<IV> + <hash(message)> + <aes(message)>)\r
pub fn decrypt(key: &str, cipher_text: &str) -> Result<String, DecryptError> {\r
/// Decrypt the given text with the given key. The key length must be 128 bits encoded in base64.\r
/// Input format: "1" + base_64(<IV> + <hash(message)> + <aes(message)>)\r
pub fn decrypt(key: &str, cipher_text: &str) -> Result<String, DecryptError> {\r
\r
// Can't decrypt a message with the wrong version.\r
if !cipher_text.starts_with(consts::CURRENT_MESSAGE_VERSION) { return Err(DecryptError::WrongMessageVersion) }\r
\r
// Can't decrypt a message with the wrong version.\r
if !cipher_text.starts_with(consts::CURRENT_MESSAGE_VERSION) { return Err(DecryptError::WrongMessageVersion) }\r