teavault - a header-only compile-time string encryption functionality using the tiny encryption algorithm (tea).
- compile-time encryption to resist static string extraction
- automatic or manual decryption at runtime
- per-use key derivation from call-site seeds and literal bytes
- scoped decrypted buffers that wipe themselves on destruction
- order scrambling that covers every encrypted block exactly once
- optional custom seeds
the encryption uses the tea algorithm with a 128-bit key. by default, tea_str and tea_str_m derive per-use seeds from the expansion site (__LINE__, __COUNTER__, __FILE__), build timestamp, TEA_STR_BUILD_SEED, and the literal bytes. you can also provide custom seed values to generate the key.
TEA_STR_BUILD_SEED defaults to 0. define it from your build system if you want a build-specific seed:
g++ -DTEA_STR_BUILD_SEED=0x9a7f31c2u ...this is string obfuscation, not a cryptographic secret store: runtime decryption requires enough key material to exist in the binary.
#include <iostream>
#include "tea_str.hpp"
int main() {
// automatic decryption with default key generation
auto decrypted_str = tea_str("automatically decrypted string!");
// manual decryption object
auto encrypted_obj = tea_str_m("manually decrypted string");
// custom seed key generation
auto custom_seed_str = tea_str("custom seed example", 1234, 5678, 91011, 1213);
std::cout << "automatic decryption: " << decrypted_str << "\n";
std::cout << "manual decryption: " << encrypted_obj.decrypt() << "\n";
std::cout << "custom seed decryption: " << custom_seed_str << "\n";
return 0;
}-
tea_str(str, ...): creates encrypted string with automatic decryptionstr: string to encrypt...: optional custom seed values- returns
tea::decrypted_string<N>, an owning scoped buffer; use.c_str()when a raw pointer is required
-
tea_str_m(str, ...): creates encrypted string object for manual decryptionstr: string to encrypt...: optional custom seed values
the key_generator::generate() method creates a 128-bit key from:
- default macro use: expansion-site seeds, build timestamp,
TEA_STR_BUILD_SEED, and the literal bytes - custom: user-provided seed values
this project is licensed under the MIT license. see the LICENSE file for details.