How string encryption works (and what it can't hide)

String encryption keeps literals — URLs, keys, messages — out of a static decompile. Here is what it actually does, and the runtime limit that matters.

Renaming hides what your members are called. It does nothing for the text sitting inside them. Every URL, connection string, API endpoint and error message you wrote as a literal is still there in plain sight. String encryption is the layer that deals with that — and it is worth understanding exactly how far it goes.

What a decompiler sees without it

String literals are stored verbatim in an assembly's metadata, in a region called the #US (user strings) heap. A decompiler does not even have to reconstruct code to read them — a plain strings dump over the file reveals the lot. So after a rename-only pass, a method named a.b() may be unreadable, but the "https://api.example.com/v2/licenses" inside it is not.

For a lot of real code that is the more valuable leak. Endpoint URLs, the shape of a request, the name of a feature flag, a telling assertion message — these map out how your software works far faster than renamed control flow does.

What string encryption does

Enabling it moves each literal out of the metadata and replaces it with a call that produces the string at runtime. In the shipped assembly the readable text is gone; what remains is an encoded blob and a small decoder the obfuscator adds. Where the code used to load a constant, it now calls the decoder with an index and gets the original value back.

The practical effect: a static decompile — the first and cheapest thing anyone does to an assembly — no longer hands over your strings. A reader sees Decode(0x1F) instead of the URL, and has to do real work to recover it.

The honest limit. The string has to exist in cleartext at the moment your code uses it, so a decryption routine is present in the assembly and runs on demand. An attacker who runs your program under a debugger, or who calls the decoder in a loop, can recover every string. String encryption raises the cost of a static read; it does not make a determined dynamic attacker's job impossible. Nothing that ships to a user's machine can — this is exactly where obfuscation differs from real encryption.

So what is it good for?

Most reverse engineering is opportunistic and static. Someone opens your assembly in ILSpy, skims for anything interesting, and moves on if it is not easy. String encryption removes the easiest possible win from that pass. It is the difference between a casual reader copying your endpoint in ten seconds and a motivated one attaching a debugger and watching the decoder — a far smaller group of people and a far larger amount of effort.

Treat it as what it is: a meaningful raise in cost, not a vault. The right threat-model framing is in what obfuscation actually protects against.

What you should still never put in a binary

Encryption of literals does not make a shipped assembly a safe place for a secret. A private signing key, a master API credential, a password — anything whose exposure is a breach — must not live in client-side code at all, encrypted or not, because the decryption happens on the attacker's machine under the attacker's control.

  • Secrets that authenticate your service belong on a server the client talks to, never in the client.
  • Per-user tokens should be issued at runtime and scoped, so a recovered one is low value and expires.
  • Configuration that merely embarrasses or informs — internal URLs, feature names, debug text — is exactly what string encryption is for.

Cost and compatibility

The runtime overhead is a function call and a cheap decode where you previously had a constant load. For the overwhelming majority of code paths this is unmeasurable. The one place to think about it is a literal pulled inside a very hot loop millions of times — and even there the usual fix (hoist the constant into a field once) is good practice regardless.

Compatibility is not usually affected, because the decoded value is identical to the original string. The rare exception is code that compares string references with object.ReferenceEquals or relies on interning of specific literals; correct code compares with == or string.Equals and is unaffected.

Where it sits in the lineup

String encryption is one of the Pro protection layers, alongside control-flow obfuscation and method virtualization. Renaming and blocking ILDasm are free and cover the most common need; string encryption is the next layer up when the literals in your code are themselves worth hiding. You can see what renaming alone does to your assembly first — obfuscate a file — and decide from there whether the string layer earns its place for your project.

Try it on your own assembly

Upload a DLL or EXE and download the obfuscated result. Free, no signup, nothing stored.