Home Upgrade Search Memberlist Extras Hacker Tools Award Goals Help Wiki Contact

[RUST] Compile-time String Encryption

[Image: Download-2.gif]
A Rust string encryption macro that encrypts strings at compile-time and decrypts them only when accessed at runtime.


Cargo.toml

Spoiler (Click to View)

lib.rs (macro)
Spoiler (Click to View)

Example
Code
use string_encryption::encrypt;

fn main() {
    println!("Encrypted message: {}", encrypt!("This is a secret message!!1"));
}

Compile-Time Encryption
  • Uses proc-macro to process strings during compilation
  • Generates random encryption keys for each string
  • No plaintext strings stored in the binary

Multi-Layer Encryption
  • Two separate 16-byte random keys
  • Multiple transformations per byte:
    • XOR encryption
    • Bit rotation
    • Position-based scrambling
    • Wrapping addition

Performance
  • Zero runtime encryption overhead
  • Minimal decryption cost

Limitations
  • Only works with string literals
  • Each encryption is unique (same string encrypted differently each compile)
  • Requires proc-macro support
looking for work
Nice, nice, a very useful method for any language. Glad to see you knocked this out in Rust.
Yes, but there is better way around it without having to use those dependencies

Code
#[macro_export]
macro_rules! obfs_str {
    ($string:expr) => {{
        const KEY: u8 = 0xAA;
        const OBFUSCATED: &'static [u8] = &{
            let mut obfuscated = [0u8; $string.len()];
            let bytes = $string.as_bytes();
            let mut i = 0;
            while i < $string.len() {
                obfuscated[i] = bytes[i] ^ KEY;
                i += 1;
            }
            obfuscated
        };
        String::from_utf8(OBFUSCATED.iter().map(|b| b ^ KEY).collect()).unwrap()
    }};
}

and use it like you do

Code
let str = obfs_str!("debugger found");

Now, I know i am using a static XOR key (0xAA) and you employ multi-step obfs, we can certainly introduce complexity in my solution without performance overhead.

but your solutiona is Computationally heavier due to complex obfuscation. I dont know why write like that for Performance.

However with your solution we can obfs really really long strings though
https://hackforums.net/showthread.php?tid=6333106

Cheap Telegram RAT written in Rust
(Jan 19, 2025 10:47 PM)Infinity. Wrote:  Yes, but there is better way around it without having to use those dependencies

Code
#[macro_export]
macro_rules! obfs_str {
    ($string:expr) => {{
        const KEY: u8 = 0xAA;
        const OBFUSCATED: &'static [u8] = &{
            let mut obfuscated = [0u8; $string.len()];
            let bytes = $string.as_bytes();
            let mut i = 0;
            while i < $string.len() {
                obfuscated[i] = bytes[i] ^ KEY;
                i += 1;
            }
            obfuscated
        };
        String::from_utf8(OBFUSCATED.iter().map(|b| b ^ KEY).collect()).unwrap()
    }};
}

and use it like you do

Code
let str = obfs_str!("debugger found");

Now, I know i am using a static XOR key (0xAA) and you employ multi-step obfs, we can certainly introduce complexity in my solution without performance overhead.

but your solutiona is Computationally heavier due to complex obfuscation. I dont know why write like that for Performance.

However with your solution we can obfs really really long strings though

Thanks for sharing your solution. It’s clean and efficient perfect for cases where minimalism is the priority, though it focuses more on simplicity than security.

My approach prioritizes security with dynamic keys and multi-step obfuscation, making reverse engineering harder. The performance impact remains negligible unless you’re decrypting many large strings at runtime.

Thanks again for HQ share!
looking for work
is this similar to https://crates.io/crates/obfstr ?

Chacha20 > AES > XOR 👎
(Feb 28, 2025 09:19 AM)Bastrile Wrote:  is this similar to https://crates.io/crates/obfstr ?

Chacha20 > AES > XOR 👎

No it's similar to you not knowing how to code even if I paid a professional programming teacher they still couldn't show you the way without a miracle.
(Feb 28, 2025 07:13 PM)Tha Sneak Wrote:  No it's similar to you not knowing how to code even if I paid a professional programming teacher they still couldn't show you the way without a miracle.

Don't read coding stuff too much, you will confuse yourself and maybe you will forget your clever methods for "removing malware". Maybe you will forget how to use Geek Uninstaller to force remove malware registry.
I assume geek.exe out of support so you are in huge problem these days...
Btw, I found a similar package doing what the thread suggests and more!

https://github.com/anvie/litcrypt.rs
https://hackforums.net/showthread.php?tid=6333106

Cheap Telegram RAT written in Rust
(Mar 13, 2025 07:22 AM)Infinity. Wrote:  Btw, I found a similar package doing what the thread suggests and more!

https://github.com/anvie/litcrypt.rs

Yes, this is one of the projects that inspired me to create my own.
looking for work
(Mar 13, 2025 09:49 AM)Klonopin Wrote:  Yes, this is one of the projects that inspired me to create my own.

That's awesome mate, let me know if you need some help or are stuck at something
https://hackforums.net/showthread.php?tid=6333106

Cheap Telegram RAT written in Rust
how about real polymorphic rust string encryption

Code
// encrypted with https://www.stringencrypt.com (v1.5.0) [Rust]
// secret = "Rust polymorphic string encryption"
let mut YITit: [u16; 35] = [ 0x6F65, 0xA401, 0x8F00, 0x8125, 0x3877, 0xBD48, 0xC551, 0x6F0B,
                             0x3F64, 0x22C8, 0xCCEC, 0x58EC, 0xB07D, 0x2CD8, 0x51E8, 0x85D5,
                             0x8A37, 0x9036, 0x0A4B, 0xA642, 0x9E3D, 0x121F, 0x69BD, 0x464F,
                             0x412D, 0xDED5, 0x0F3B, 0x3DF8, 0x4185, 0x71C2, 0x93B7, 0xFEBA,
                             0xC388, 0x2682, 0xE3E7 ];

let mut Aiptj: u16 = 0;
for IsQOo in 0..35
{
    Aiptj = YITit[IsQOo];
    for KWRyH in 0..4
    {
        Aiptj = (Aiptj & 0xFFFF).wrapping_add(IsQOo as u16) & 0xFFFF;
        Aiptj = (Aiptj & 0xFFFF).wrapping_sub(0x6D20) & 0xFFFF;
    }
    Aiptj = (Aiptj & 0xFFFF).wrapping_add(IsQOo as u16) & 0xFFFF;
    Aiptj = (Aiptj ^ 0xFFFF) & 0xFFFF;
    Aiptj = (Aiptj & 0xFFFF).wrapping_sub(IsQOo as u16) & 0xFFFF;
    for caOPY in 0..4
    {
        for OzgHv in 0..4
        {
            for dXzWl in 0..4
            {
                Aiptj = (Aiptj & 0xFFFF).wrapping_add(0xC3CD) & 0xFFFF;
                Aiptj = (Aiptj ^ 0x96EF) & 0xFFFF;
                Aiptj = ((Aiptj & 0xFFFF).wrapping_shr((IsQOo as u32) % 16u32) | (Aiptj & 0xFFFF).wrapping_shl((16u32).wrapping_sub((IsQOo as u32) % 16u32).wrapping_rem(16u32))) & 0xFFFF;
            }
            Aiptj = (Aiptj & 0xFFFF).wrapping_add(IsQOo as u16) & 0xFFFF;
            for HWDoZ in 0..2
            {
                Aiptj = ((Aiptj ^ 0xFFFF).wrapping_add(1)) & 0xFFFF;
            }
        }
        Aiptj = (Aiptj & 0xFFFF).wrapping_add(0x02CE) & 0xFFFF;
    }
    Aiptj = (Aiptj ^ (((Aiptj & 0xFFFF).wrapping_shl((14u32) & 15)) & 0xFFFF)) & 0xFFFF;
    YITit[IsQOo] = Aiptj;
}
let secret = String::from_utf16_lossy(&YITit[..]);


Possibly Related Threads...
Thread / Author Replies Views Last Post
by Infinity.Sep 24, 2026 10:01 AM 5 474 Sep 24, 2026 10:01 AM
Last Post: Anonynuk
[C] by PELockApr 14, 2026 01:15 PM 0 126 Apr 14, 2026 01:15 PM
Last Post: PELock
[The Brotherhood] by HackersApr 10, 2026 02:15 AM 22 2,142 Apr 10, 2026 02:15 AM
Last Post: PELock