Menu

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.

Obfuscation Studio Free
Ready
C# Source 0 lines • 0 chars
Obfuscated Output 0 lines • 0 chars
Obfuscation Options
All processing runs in your browser. Your code is never uploaded. This obfuscates source — it does not protect a compiled .dll/.exe. See "Does this protect my compiled .dll?" in the FAQ below.
Complete Guide to C# Obfuscation

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).

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

  1. Tokenize. A hand-written tokenizer splits the source into identifiers, keywords, string/char/verbatim/interpolated literals, numbers, punctuation, preprocessor directives, and comments.
  2. Remove comments. Comment tokens are dropped (string- and char-literal aware).
  3. 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.
  4. 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.
  5. Rename identifiers. Every identifier token matching a candidate is replaced with a short generated name, consistently within its own scope.
  6. Reconstruct source. Tokens are re-emitted with the minimum whitespace required to keep the result syntactically valid C#.
  7. 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 is not validated: actual C# compilation and runtime behaviour equivalence. Always build and run the obfuscated file in your own project before relying on it, and keep the original source under version control.

What's Safe vs Unsafe to Rename

ConstructRenamed?Reason
Local var / typed variableYesNot observable outside its method
Method / constructor parametersYesBound by position, not by name, at call sites
foreach loop variableYesScoped to the loop body
catch (Exception ex) variableYesScoped to the catch block
Lambda parametersYesScoped to the lambda expression
Class / struct / interface / enum / record namesNoPart of the public type surface
Method and property namesNoMay be called externally or via reflection
Field namesNoMay be serialized, bound in the Inspector, or accessed via reflection
nameof(x) contentsNoMust keep matching the identifier it names
Namespace & using directivesNoMust match assembly/module structure
Attribute argumentsNoOften consumed by reflection at runtime
Verbatim / interpolated stringsNoMay 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 or nameof() 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?
A C# obfuscator rewrites readable .cs source into a form that is harder for a human to follow while preserving identical runtime behavior. Typical transformations include renaming local variables and parameters, encoding string literals, and removing comments.
Is this C# obfuscator free?
Yes. The tool is completely free with no registration, no file limits, and no hidden fees. All processing happens in your browser.
Does this protect my compiled .dll or .exe?
No, and this is the most important thing to understand. This tool rewrites your .cs source text before you compile it. Once compiled, a decompiler such as ILSpy, dnSpy, or dotPeek reconstructs readable C# directly from the IL metadata of your assembly, independent of how your original source was named. To protect a shipped binary you need an IL-level obfuscator such as ConfuserEx, Obfuscar, Babel, or Dotfuscator, which operate on the compiled assembly itself.
Then what is this tool actually useful for?
Protecting source-level readability in contexts where the .cs file itself is what gets shared or exposed: internal scripts, code pasted into tickets or forums, Unity scripts distributed as source in an asset package, teaching/interview anti-cheating, or reducing casual copy-paste reuse of logic shared as plain text.
Is my code uploaded to your server?
No. The obfuscator runs entirely as JavaScript inside your browser. Your C# source code never leaves your device.
Does obfuscation break my code?
The tool only renames identifiers it can determine are purely local (method-body variables and parameters) and only encodes plain double-quoted string literals. It performs a structural validation pass (brace, bracket, and quote balance) after transformation. Code using reflection, nameof(), dynamic, or runtime string-keyed lookups on renamed identifiers can still break — these are documented limitations above.
Which C# versions are supported?
The tokenizer recognizes modern C# syntax including records, pattern matching, nullable reference types, top-level statements, async/await, LINQ, and interpolated strings. Verbatim (@"...") and interpolated ($"...") strings are left untouched rather than encoded, to avoid corrupting embedded expressions.
Can obfuscated C# source be reversed?
Source-level obfuscation is a deterrent, not encryption. Anyone with the obfuscated .cs file can still compile and run it, and a careful reader can trace renamed locals by following control flow. Never embed real secrets, connection strings, or API keys in any C# file, obfuscated or not.
Does obfuscation affect performance?
None at the IL/runtime level beyond a negligible one-time cost: each encoded string is decoded once when first evaluated via Convert.FromBase64String and a byte XOR loop, which the JIT compiles like any other method.
Will it break public classes, methods, or properties?
No. This tool deliberately never renames class, struct, interface, enum, namespace, method, property, or field names — only identifiers declared and consumed purely inside a method body (local variables and parameters). Public API surfaces and field/property names stay exactly as written.
Does this work with Unity?
Yes for plain C# scripts, with care: avoid renaming locals inside MonoBehaviour methods that Unity's serializer or the Inspector references by string (e.g. SendMessage targets, reflection-based editor tooling). Public fields exposed in the Inspector are never renamed by this tool.
Does it work with ASP.NET Core or Blazor?
It works on plain .cs files. Razor (.cshtml/.razor) markup is not parsed by this tool — extract the C# code-behind or @code block first, obfuscate that, then paste it back.
What does string encoding do?
Regular double-quoted string literals are Base64-encoded and XORed with a per-build key, then wrapped in a call to a small generated decoder class. This hides plain strings from a quick text search or decompiled-string scan but is not cryptographic security.
Can I use this commercially?
Yes. You may obfuscate any code you own or have rights to modify and distribute the output under your own license.
What identifiers are safe to rename?
Local variables declared with var or an explicit type inside a method body, foreach loop variables, catch-block exception variables, and method parameters — none of which are observable from outside the method. Fields, properties, methods, types, and namespaces are left untouched.
Does it preserve nameof() and reflection?
nameof() targeting a local or parameter that gets renamed will no longer match, since this tool does not rewrite the contents of nameof() expressions. Disable variable renaming for files that lean on nameof() against locals, or review the diff before shipping.
What is the difference between obfuscation and minification?
Minification reduces file size by collapsing whitespace. Obfuscation targets readability — making the logic harder to follow. C# is compiled, so minification here mainly helps when the .cs file itself is distributed as source (e.g. a Unity asset), not for runtime performance.
Will it break LINQ or lambda expressions?
Lambda parameters (e.g. x => x.Value) are treated as local to the lambda and may be renamed consistently within it. Expression trees that inspect parameter names via reflection (common in some ORMs) can break — review such files manually or disable renaming for them.
How is the output validated?
This tool cannot run a full Roslyn/C# compiler in the browser, so it performs a structural validation pass: it re-tokenizes the obfuscated output and checks that every brace, bracket, parenthesis, and string/char literal is correctly balanced and terminated. This catches reconstruction bugs but is not a substitute for compiling the result yourself, which you should always do before shipping.
Can obfuscation be detected?
Yes. A reviewer opening the file will immediately see short renamed identifiers and a decoder helper class. This tool is for reducing casual readability, not for hiding the fact that obfuscation occurred.

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.