tiny_crypto/
lib.rs

1//! The [`tiny-crypto`](crate) is a collection of tools for common crypto algorithms, 
2//! with APIs aimed to be simple to use.
3//! 
4//! # Table of tools
5//! * Cryptographic Hash Functions ([`hash`](mod@crate::hash))
6//!   - Sha1
7//! * Symmetric Ciphers ([`sym`])
8//!   - Aes128, Aes192, Aes256
9//! * Text Encoders ([`encoding`])
10//!   - Base64
11//! 
12//! # Example
13//!
14//! Use sha1 hasher:
15//! ```rust
16//! let result: Vec<u8> = tiny_crypto::sha1!(b"abcdefghijklmn", b"opqrstuvwxyz");
17//! assert_eq!(result, tiny_crypto::sha1!(b"abcdefghijklmnopqrstuvwxyz"));
18//! 
19//! let hex_result: String = tiny_crypto::sha1_hex!(b"abcdefgh");
20//! assert_eq!(hex_result, "425af12a0743502b322e93a015bcf868e324d56a");
21//! ```
22//! 
23//! Use Aes128 cipher:
24//! ```rust
25//! use tiny_crypto::sym::{Cipher, Aes128};
26//! let cipher = Aes128::from_key_array(b"This is the key!");
27//! let plain = b"This is the plain text";
28//! let iv = [0x66u8; 16];
29//! let data = cipher.encrypt_with_iv(&iv, plain);
30//! let out = cipher.decrypt_with_iv(&iv, &data);
31//! assert_eq!(out, plain);
32//! ```
33//! 
34//! Use Base64 encoder:
35//! ```rust
36//! use tiny_crypto::encoding::{Encoder, BASE64};
37//! let origin: &[u8] = b"some bytes to encode";
38//! assert_eq!(origin, &BASE64.from_text(&BASE64.to_text(origin)).unwrap());
39//! ```
40//! 
41//! Use Hex encoder:
42//! ```rust
43//! use tiny_crypto::encoding::{Encoder, HEX};
44//! let origin: &[u8] = b"some bytes to encode";
45//! assert_eq!(origin, &HEX.from_text(&HEX.to_text(origin)).unwrap());
46//! ```
47//! 
48
49pub mod hash;
50pub mod sym;
51pub mod encoding;