Expand description
XOR encryption algorithm implementation.
This module provides a simple XOR-based encryption algorithm. While not cryptographically secure, it is fast and suitable for basic obfuscation of secrets in compiled binaries.
§Algorithm
The Xor algorithm uses a single-byte key that is XOR’d with each
byte of the plaintext. The same operation is used for both encryption
and decryption (XOR is its own inverse).
§Types
Xor<KEY, D>: The main algorithm type with const generic key and drop strategyReEncrypt<KEY>: A drop strategy that re-encrypts data on drop
§Example
use const_secret::{
Encrypted, StringLiteral,
drop_strategy::Zeroize,
xor::{ReEncrypt, Xor},
};
// Zeroize on drop (default)
const SECRET: Encrypted<Xor<0xAA, Zeroize>, StringLiteral, 5> =
Encrypted::<Xor<0xAA, Zeroize>, StringLiteral, 5>::new(*b"hello");
// Re-encrypt on drop
const SECRET2: Encrypted<Xor<0xBB, ReEncrypt<0xBB>>, StringLiteral, 6> =
Encrypted::<Xor<0xBB, ReEncrypt<0xBB>>, StringLiteral, 6>::new(*b"secret");
fn main() {
let s1: &str = &*SECRET;
assert_eq!(s1, "hello");
let s2: &str = &*SECRET2;
assert_eq!(s2, "secret");
}