Crates.io | base64-secret |
lib.rs | base64-secret |
version | 0.1.1 |
source | src |
created_at | 2023-02-17 03:56:10.072725 |
updated_at | 2023-02-17 04:16:04.045605 |
description | Base64 encoder/decoder with custom alphabet. The alphabet is sorted by a given key. The sorting is always deterministic. |
homepage | |
repository | https://github.com/crodas/base64-secret-rs |
max_upload_size | |
id | 787243 |
size | 9,083 |
This is a Rust crate that provides an extension to the Base64 encoding algorithm. It allows for the alphabet to be shuffled according to a given key, making it harder to decode data without knowledge of the same key used to encode it.
This crate is not by any means cryptographically secure, it was designed to be fast and to be compatible with the slower scripting languages. Do not rely on to encrypt any sensible data, it was designed to be used as a simple obfuscation method.
To use this crate, add the following line to your Cargo.toml file:
cargo add base64-secret
To optimize the usage, and avoid calculating the position of each character in the alphabet over and over, it is calculated when the struct is created.
use base64_secret::Base64;
let engine = Base64::new(b"my secret key");
let data = b"This is a secret message";
let encoded_data = engine.encode(&data);
println!("{}", encoded_data); // prints "v-O0BPA0BPAOhl1yZm9yJQAuRz1XZ7Jy"
To decode is quite simple as well:
use base64_secret::Base64;
let engine = Base64::new(b"my secret key");
let encoded_data = "jPF_7wA_7wAFLXlCbaHCzQAS3flubnzC";
let data = engine.decode(&encoded_data).unwrap();
println!("{}", String::from_utf8_lossy(&data)); // prints "This is a secret message"
Contributions are welcome! If you find a bug or have a feature request, please open an issue on the GitHub repository. If you'd like to contribute code, please open a pull request.
This crate is licensed under the MIT license. See the LICENSE file for more information.