C# / .NET Obfuscator
Renames local variables and parameters, encodes string literals with a matching runtime decoder, and strips comments from your .cs source — entirely in your browser. Every output is re-checked for structural integrity before it's shown to you.
C# obfuscation rewrites readable .cs source into a form that is harder for a human to follow, while preserving the exact runtime behaviour of the original program. This tool uses a hand-written C# tokenizer to find identifiers it can safely rename — local variables and parameters only — and performs a structural validation pass on its own output before showing it to you.
Read this before you rely on it: C# is compiled to IL, and IL carries its own metadata (type names, member names) independent of your original source file. Renaming identifiers in a .cs file does nothing to protect a compiled assembly — a decompiler reconstructs readable code straight from the IL, regardless of how the source was named before compilation. This tool protects source text that is shared or exposed as-is; for a shipped .dll or .exe you need an IL-level obfuscator (see the Limitations section).
Table of Contents
What is C# Obfuscation?
At the source level, C# obfuscation is the process of transforming a .cs file into an equivalent file that is harder to read or copy, without changing what it does once compiled. This is distinct from IL obfuscation, which transforms the compiled assembly itself — renaming metadata, encrypting method bodies, flattening control flow — and is what real-world shipped applications typically need for actual reverse-engineering resistance.
This tool operates at the source level. It's the right fit when the thing you're protecting is the .cs text itself — for example a script bundled as source, a snippet shared externally, or a file in a public repository — not a binary you've already built.
Techniques Used by This Tool
Local Variable & Parameter Renaming
The tokenizer scans each method body for var/typed local declarations, foreach loop variables, catch exception variables, and parameter lists, then renames only identifiers that are never observed outside that method. Class, struct, interface, enum, namespace, method, property, and field names are never touched.
String Literal Encoding
Plain double-quoted string literals are encoded as Base64 bytes XORed with a per-build key, decoded at runtime through a small generated helper class (Convert.FromBase64String + a byte loop). Verbatim @"..." and interpolated $"..." strings are intentionally left as-is to avoid corrupting embedded expressions or escape sequences.
Comment Removal
The tokenizer distinguishes real // and /* */ comments from string and char literal contents, so a comment-like sequence inside a string is never stripped.
Whitespace Minification
Optional. Collapses formatting to reduce file size without changing semantics — useful mainly when the .cs file is distributed as source rather than compiled on your own machine.
How the Tool Works
- Tokenize. A hand-written tokenizer splits the source into identifiers, keywords, string/char/verbatim/interpolated literals, numbers, punctuation, preprocessor directives, and comments.
- Remove comments. Comment tokens are dropped (string- and char-literal aware).
- Scan declarations. A lightweight scope pass walks each method body (tracked by brace depth) and records locals, loop variables, catch variables, and parameters as rename candidates, skipping anything also used as a type, member, or namespace name.
- Encode strings. Eligible string literal tokens are replaced with calls into a generated decoder class; the class is appended once at the top of the file.
- Rename identifiers. Every identifier token matching a candidate is replaced with a short generated name, consistently within its own scope.
- Reconstruct source. Tokens are re-emitted with the minimum whitespace required to keep the result syntactically valid C#.
- Validate structurally. The output is re-tokenized and checked for balanced braces/brackets/parentheses and properly terminated literals. See the note below on what this does and doesn't catch.
Output Validation
A browser cannot run the Roslyn C# compiler, so this tool cannot fully verify that its output compiles. Instead it re-tokenizes the obfuscated result and confirms that every brace, bracket, parenthesis, and string/char literal is balanced and correctly terminated — the class of error most likely to be introduced by a renaming/reconstruction bug.
What's Safe vs Unsafe to Rename
| Construct | Renamed? | Reason |
|---|---|---|
Local var / typed variable | Yes | Not observable outside its method |
| Method / constructor parameters | Yes | Bound by position, not by name, at call sites |
foreach loop variable | Yes | Scoped to the loop body |
catch (Exception ex) variable | Yes | Scoped to the catch block |
| Lambda parameters | Yes | Scoped to the lambda expression |
| Class / struct / interface / enum / record names | No | Part of the public type surface |
| Method and property names | No | May be called externally or via reflection |
| Field names | No | May be serialized, bound in the Inspector, or accessed via reflection |
nameof(x) contents | No | Must keep matching the identifier it names |
| Namespace & using directives | No | Must match assembly/module structure |
| Attribute arguments | No | Often consumed by reflection at runtime |
| Verbatim / interpolated strings | No | May contain embedded expressions or escapes |
Use Cases
Unity Scripts Shared as Source
Asset-store packages and shared Unity projects often ship raw .cs files. Obfuscating method-body logic discourages casual copy-paste reuse while leaving public fields and Inspector bindings untouched.
Internal Tooling & Scripts
Hide implementation details of internal automation or build scripts when pasting them into tickets, wikis, or third-party support requests.
Coursework & Interview Exercises
Obscure a reference solution's local logic while keeping its public method signatures intact for grading or discussion.
Pre-Build Source Hardening
One step in a broader pipeline — obfuscate source, then additionally run an IL obfuscator (ConfuserEx, Obfuscar) on the compiled output for real binary protection.
Limitations & Legal
- Not binary protection. This is the single most important limitation — see the callout at the top of this guide. Compiled assemblies need an IL-level obfuscator (ConfuserEx, Obfuscar, Babel Obfuscator, Dotfuscator, Eazfuscator.NET), not source renaming.
- Not encryption. String encoding here is reversible by design (the decoder ships right alongside it). Never embed real secrets, API keys, or connection strings in any C# file.
nameof()and reflection. Code that reads a renamed local or parameter's name via reflection ornameof()will see the new, obfuscated name.- Dynamic/string-keyed lookups. Identifier names resolved at runtime from strings (dynamic, some serializers, some DI patterns on locals) cannot be safely renamed — review such files manually.
- Razor files. .cshtml/.razor markup isn't parsed; extract the C# code block first.
- Legal. Only obfuscate code you own or have rights to modify. Do not obfuscate open-source code in ways that violate its license.
Related Obfuscators
Frequently Asked Questions
What is a C# obfuscator?
Is this C# obfuscator free?
Does this protect my compiled .dll or .exe?
Then what is this tool actually useful for?
Is my code uploaded to your server?
Does obfuscation break my code?
Which C# versions are supported?
Can obfuscated C# source be reversed?
Does obfuscation affect performance?
Will it break public classes, methods, or properties?
Does this work with Unity?
Does it work with ASP.NET Core or Blazor?
What does string encoding do?
Can I use this commercially?
What identifiers are safe to rename?
Does it preserve nameof() and reflection?
What is the difference between obfuscation and minification?
Will it break LINQ or lambda expressions?
How is the output validated?
Can obfuscation be detected?
Conclusion
Source-level C# obfuscation is a narrow, honest tool: it makes a .cs file less readable without changing what it does, and it does that part well — while being upfront that it is not a substitute for IL-level protection of a compiled assembly. Combine it with proper secret management (never in source, obfuscated or not), an IL obfuscator for anything you actually ship as a binary, and standard legal protections for anything you distribute.