EnvObfuscator 2.2.3
See the version list below for details.
dotnet add package EnvObfuscator --version 2.2.3
NuGet\Install-Package EnvObfuscator -Version 2.2.3
<PackageReference Include="EnvObfuscator" Version="2.2.3" />
<PackageVersion Include="EnvObfuscator" Version="2.2.3" />
<PackageReference Include="EnvObfuscator" />
paket add EnvObfuscator --version 2.2.3
#r "nuget: EnvObfuscator, 2.2.3"
#:package EnvObfuscator@2.2.3
#addin nuget:?package=EnvObfuscator&version=2.2.3
#tool nuget:?package=EnvObfuscator&version=2.2.3
<div align="center">
EnvObfuscator
Generates Obfuscated Properties from .env File Content
</div>
- Generates
public static Memory<char>properties for each.enventry. - Generates
Validate_<PropertyName>(ReadOnlySpan<char>)for constant-time comparison.
🚀 Getting Started
To avoid embedding "raw data" as an assembly metadata, EnvObfuscator uses preceding block comment as a source.
using EnvObfuscator;
/*
# 👇 Copy & paste .env file content
API_KEY=abc123
SERVICE_URL=https://example.com
SECRET=PA$$WORD
EMPTY=
*/
[Obfuscate(seed: 12345)] // Omit the argument to use random seed
static partial class EnvSecrets
{
}
How to use the generated properties:
// Always returns a freshly decoded clone each time
var apiKey = EnvSecrets.API_KEY;
var cache = apiKey.ToString();
// Consuming decoded data...
// Zeroing out the span — more for peace of mind than actual security
apiKey.Span.Clear();
cache = "";
// Validation (no decoding, full-length compare to avoid timing differences)
if (EnvSecrets.Validate_SECRET("PA$$WORD"))
{
//...
}
Diagnostics
- Missing multiline comment yields a warning.
- Invalid lines are ignored and reported (first invalid line is shown).
- Invalid keys (non-identifiers, invalid characters, or duplicates) are errors.
- Seed value
0is allowed but warned (deterministic and predictable). - Obfuscation keys must be non-zero (error); change the seed to generate different keys.
Known Limitations
Obfuscated name collisions can surface as compiler errors, e.g.:
error CS0101: The namespace '<random_namespace>' already contains a definition for '<random_class>' or similar.
🕹️ Technical Specs
- Each non-empty, non-
#line is parsed asKEY=VALUE(split on the first=).- Keys/values are trimmed; values may contain
=after the first.
- Keys/values are trimmed; values may contain
- Keys must already be valid C# identifiers.
- Invalid characters or keywords cause an error.
- Duplicate names cause an error.
Validate_<PropertyName>(ReadOnlySpan<char>)short-circuits only on length mismatch, then performs a full-length compare to avoid leaking timing information.- Clear decoded values with
Span.Clear()after use to zero sensitive data. - Obfuscation details:
- Builds a base character table from all values + a default extra set.
- Duplicates the table, XOR-encodes with odd/even keys, then shuffles.
- Random helpers are emitted into random namespaces with random class/field names.
seed(if provided) controls the output deterministically.- The type’s assembly-unique identifier is mixed into the seed so each target differs.
Values are trimmed; leading/trailing spaces are not preserved.
Learn more about Target Frameworks and .NET Standard.
-
.NETStandard 2.0
- Microsoft.CodeAnalysis.CSharp (>= 4.0.1)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.