I have a concrete problem but I'm afraid it might be a duplicate or in violation of another rule, and I've been told that the SO meta is an adequate place to ask feedback on possible questions. The question would be as such:
I'm writing a small rust CLI program that prints a message to the user after they have solved a task. Normally, string literals or constants are stored in clear in a binary, so the
strings
command and some heuristic withgrep
will usually reveal whatever string the developer would like to hide.
Rust already has a tool for hiding string literals (theobfstr
crate) but it only generates temporary values and my problem has to do with constants: due to its length, the message is imported from a text file viainclude_str!
as aconst
. This means that i should encrypt it at the time of declaration and use a function to generate a temporary decryption at the moment of usage
Is there a Rust crate that handles compile-time obfuscation of constant strings?
Would this be answered or removed?
EDIT: After reading the feedback, I'd rephrase the question as the following:
I'm writing a small rust CLI program that asks the user to complete a task and then outputs a message (stored in a
const &str
). Normally, string constants in a compiled program are easily read via thestrings
command and I would like to obfuscate the final message at least from this casual degree of examination. The code would probably look like this:const obfuscated_message = encrypt!("This is the secret message"); fn main() { // User task let message: &str = decrypt!(obfuscated_message); println!("{}",message); }
Looking for solutions to this problem, I found the obfstr crate, which works well if you only need to use the string a single time, but only works in-place and does not scale very well.
How do I define a rustconst &str
such that it can be used elsewhere in the program but won't appear in clear in the compiled executable?
Is this version more likely to get answered?
const &str
at compile time?" is closer to the mark, but you'll still need to specify what it actually means to "obfuscate" the string.