Skip to content
← All posts
· Delta1 Labs ObfuscationNebula

Can obfuscation hide a connection string? What Nebula protects, and what it cannot

A connection string, an API key or a signing secret that ships inside your .NET app is recoverable in principle — the process has to use it, so the process has to hold it. This is an honest comparison of the three places a secret hides in a shipped assembly, exactly what Nebula.NET string and resource encryption change about each, where the ceiling is, and the layering that actually keeps a secret out of an attacker's hands.

Every protection tool gets the same question, usually phrased as a demand: “I have a connection string in my desktop app — can you make it so nobody can read it?” The honest answer is a comparison, not a yes. A secret that ships inside client-side code is recoverable in principle, because the process has to use it, which means the process has to hold the plaintext at some instant. What obfuscation changes is the cost of recovery — from “double-click a resource viewer” to “attach a debugger, find the decode, reproduce it” — and whether the string is sitting in cleartext for a strings.exe dump or a web crawler to find.

This post is the comparison in full. Where a connection string actually hides in a shipped assembly, what Nebula.NET string and resource encryption do to each hiding place, where the ceiling is and why, and the layering that keeps the secret out of the binary entirely when it can.

The three places a secret hides

A connection string, an API key, a symmetric key for an embedded data file — all of them reach the shipped assembly through one of three routes, and each decompiles differently.

As a literal in code. The most common and the most exposed:

const string Conn = "Server=db.internal;Database=App;User Id=svc;Password=S3cr3t!;";

The C# compiler emits that as a single ldstr into the string heap. It is not encrypted, not encoded, not hidden — it is UTF-16 text in a well-known table:

ldstr      "Server=db.internal;Database=App;User Id=svc;Password=S3cr3t!;"

As an embedded appsettings.json resource. You set the file to EmbeddedResource so it travels inside the DLL:

<ItemGroup>
  <EmbeddedResource Include="appsettings.Production.json" />
</ItemGroup>

Now the JSON — connection strings and all — is a length-prefixed blob in the ManifestResource table. No decompiler needed; System.Resources reads it, and so does every resource viewer.

As a value bound through configuration. The string lives in appsettings.json on disk and is read by IConfiguration into an options POCO. This is the only one of the three that is not in the assembly — but it is a plaintext file sitting next to the binary, which is a different exposure, not a smaller one.

Note the split: the first two ship the secret inside the binary, where obfuscation can act on it; the third ships it beside the binary, where obfuscation cannot reach it at all. That distinction drives the whole comparison.

DEFAULT EXPOSUREAFTER NEBULARUNTIME CEILINGconst literalin code (ldstr)"...Password=S3cr3t!"plaintext in string heapstringEncryption →decode call, no literalheld decryptedin memory at useembeddedappsettings.jsonJSON blob in manifestany resource viewer reads itresourceEncryption →ciphertext, resolver decryptsdecrypted whenthe config is readon-diskconfig fileplaintext file beside thebinary — outside the DLLobfuscation cannotreach it — move it outread into processmemory on loadRed = readable in one step · Green = raised to reverse-engineering · Grey = not in the assembly

What a decompiler sees before protection

Open an unprotected build in Glass.NET (or any decompiler) and the literal case needs no effort at all. The IL view shows the ldstr; the string heap view lists the value. You do not even have to find the method — a decompiler’s metadata browser lists every string in the assembly, and Server=…;Password=…; sorts right next to your error messages.

The embedded-resource case is worse, because it does not require a decompiler at all. Expand the assembly’s resources node and the appsettings.Production.json resource is right there; one click dumps the JSON. The BCL even ships the reader, so a five-line program recovers it:

var asm = Assembly.LoadFile(path);
using var s = asm.GetManifestResourceStream("MyApp.appsettings.Production.json");
using var r = new StreamReader(s!);
Console.WriteLine(r.ReadToEnd()); // connection strings and all

“I compiled it into the DLL” is not protection. It is a slightly less obvious filename.

What Nebula changes, concretely

Nebula.NET acts on the two in-assembly cases. String encryption rewrites the literal. The ldstr is replaced by a call to a generated decode routine that takes an opaque token and returns the plaintext at the point of use:

ldc.i4     0x3f91a7
call       string <Nebula>.Decode(int32)

The cleartext connection string is gone from the string heap. A metadata browser now lists an encoded blob; a strings dump finds nothing; a decompiler shows a call into protected code rather than a value. You scope it in nebula.config.json so the valuable literals are covered without taxing a measured hot path:

{
  "schemaVersion": 1,
  "inputs": [ "bin/Release/net8.0/MyApp.dll" ],
  "outputDirectory": "protected",

  "stringEncryption": {
    "enabled": true,
    "include": [ "MyApp.Data.*", "MyApp.Security.*" ]
  },

  "resourceEncryption": {
    "enabled": true,
    "include": [ "MyApp.appsettings.Production.json" ],
    "exclude": [ "*.g.resources" ]
  },

  "controlFlow": { "enabled": true }
}

Resource encryption handles the embedded JSON. The pass replaces the plaintext resource bytes with ciphertext at build time and installs a resolver so that GetManifestResourceStream — and therefore the configuration provider that reads it — receives a decrypting stream for the protected names. Your call site is unchanged:

var config = new ConfigurationBuilder()
    .AddJsonStream(Assembly.GetExecutingAssembly()
        .GetManifestResourceStream("MyApp.appsettings.Production.json")!)
    .Build();

This still binds, because the resolver decrypts transparently. What changed is only what a static viewer sees on disk: ciphertext, not a connection string. Run it with:

nebula protect --config nebula.config.json --out bin/Protected

Both passes do the same thing in different parts of the PE: they remove the trivial disclosure — the value you could read in one step — and force any recovery through the obfuscated code, where it costs real effort. That is the entire, honest claim.

The ceiling, and why it exists

Here is the part a vendor should state plainly: encryption does not make a client-side secret unrecoverable. The decryption key ships in the assembly too, because the process must decrypt the value to use it. Nebula derives that key through the same protected code path that guards your methods — it is not a constant sitting in a field — so recovering it means reverse-engineering control-flow-flattened, string-encrypted code rather than reading a literal. That is a large increase in cost. It is not infinity.

The sharper limit is runtime. The instant your code does this:

using var conn = new SqlConnection(decryptedConnString);

the plaintext connection string exists as a live string on the managed heap. An attacker who can run your process — which, on a client machine, they can — can attach a debugger, break on SqlConnection..ctor, and read the argument. No decompilation required. The same is true of the decrypted appsettings.json: once the configuration provider has read it, the values are objects in memory. Obfuscation raises the bar against static inspection and against casual dumps. It cannot win against a debugger attached to a process that is about to use the secret, because at that moment the secret is, by necessity, plaintext.

This is not a weakness specific to Nebula; it is the nature of client-side secrets. Any tool that claims otherwise is selling the claim, not the protection.

The layering that actually works

Because of that ceiling, the real strategy is a hierarchy, and obfuscation is the last tier, not the first.

Tier 1 — do not ship the secret. A connection string to a server you control, a third-party API key, anything that authenticates the client to a backend: this should not be in the binary at all. Keep it out of source with user-secrets in development, supply it from an environment variable or your platform’s managed identity in production, or — best — never hand the client a long-lived credential and instead broker access so the server issues a short-lived, scoped token. A secret that is never in the artifact has no recovery cost because there is nothing to recover. Obfuscation is irrelevant to Tier 1, and that is the point: the strongest protection is absence.

Tier 2 — for the secret you genuinely must embed, raise the cost. Some secrets have to ship: the public key your app uses to verify a license, a symmetric key that decrypts an embedded proprietary data file, a pinned certificate. These cannot be moved to a server because the app must function offline or must not trust the network for this check. For these, Nebula is exactly the right tool. Encrypt the literal, encrypt the resource, flatten the control flow around the derivation, and — for the highest-value routine — virtualize the method so the key derivation runs on an interpreted instruction set rather than readable IL. You are not making recovery impossible; you are making it expensive enough that it is not worth it relative to what the secret protects.

The decision is a short table.

The secretCan it leave the binary?Treatment
DB connection string, backend API keyYes — authenticates to your serverTier 1: broker it, issue short-lived tokens
Third-party key tied to your accountUsuallyTier 1: proxy the call through your backend
License-verification public keyNo — must verify offlineTier 2: ship it, string-encrypt + control-flow
Symmetric key for an embedded data fileNo — app must decrypt locallyTier 2: resource-encrypt + virtualize the derivation

The mistake is to skip Tier 1 and ask obfuscation to do its job. Obfuscation makes a must-ship secret costly to extract. It does nothing to justify shipping a secret that never needed to be there.

Verify what you shipped

After a protected build, confirm the two in-assembly cases are actually closed. Open protected/MyApp.dll in Glass.NET: the string heap should no longer list your connection string, and the appsettings.Production.json resource should dump as ciphertext, not JSON. Make it a CI gate — a script that opens the protected output, asserts no resource decodes to recognizable JSON and no literal matches a Password= pattern, and fails the build if either does. That catches the day someone adds a new secret-bearing literal to a namespace your include list does not cover.

A protected binary that still grep-matches your password means the pass did not reach it; a clean one means you have done everything client-side obfuscation can do — and told the truth about where that ends.

See Nebula.NET for the full transform pipeline and the nebula.config.json reference, encrypting embedded resources for the resource pass in depth, and Glass.NET for verifying what a decompiler can still read.

Try Nebula.NET

Harden your .NET code in minutes — start with the free edition.