Skip to content
This repository has been archived by the owner on May 3, 2023. It is now read-only.

Latest commit

 

History

History
39 lines (30 loc) · 1.04 KB

README.md

File metadata and controls

39 lines (30 loc) · 1.04 KB

Build Status
XXTEA encryption algorithm library

What is XXTEA

see this page

Example

extern crate xxtea;
extern crate base64;

use base64::{encode, decode};
use std::str;

fn main() {
    let data = "Hello World";
    let key = "This is the key";

    // encrypt
    let result: String = encode(xxtea::encrypt(&data, &key).as_slice());
    println!("{}", result); // will output GEvbeEorvUJmCT2A2j5bGw==

    // decrypt
    let plain_bytes: Vec<u8> = xxtea::decrypt(&decode(&result).unwrap(), &key);

    let plain_texts = match str::from_utf8(plain_bytes.as_slice()) {
        Ok(v) => v,
        Err(e) => panic!("Invalid UTF-8 sequence: {}", e),
    };
    println!("{}", plain_texts);  // will output Hello World
}

Contributor

Daniel

LICENSE

MIT