This is a Nim library for automatic encryption (currently via XOR with a different key for each string generated at compile-time) of string literals. You can install it from Nimble via
nimble install strenc
and then just use it like so:
import strenc
# After importing the module you don't have to do anything else to activate encryption
echo "hello world"
echo "how are you?"
In compiled C code (or in any other backend, strenc works with all of them, although with the JS backend it'll be much easier for "interested" people to get the original contents back) strings will look like this:
STRING_LITERAL(TM__huvhZYSc4ExMXNTyiw83eQ_2, "as{xz2d\177cr{", 11);
STRING_LITERAL(TM__huvhZYSc4ExMXNTyiw83eQ_3, "kov\036^NX\032BWL\011", 12);
If you wish to disable all hints for places where the encryption was applied, add hint("Pattern", false)
to your .nims
config file, or, if you use .cfg
, --hint[Pattern]:off
Please do not forget to strip your binaries if you want this library to be useful! Otherwise it'll be much easier to find the code which does string decryption.
This library uses one of the lesser known Nim features - term-rewriting macros. They allow to implicitly rewrite code at compile-time by using different kinds of patterns. You can read more in the manual here.
Because it's fun and this library can actually help you to protect string data in the application from not-so-experienced "haxxors".