XorInterceptor intercepts comment-style calls to Xor() at compile time preventing string literals to show up in the IL.
$ dotnet add package XorInterceptorA .NET Interceptor which does a simple XOR encryption at compile time, without embedding the plaintext literal in your IL.
It scans the syntax tree for calls named Xor with zero arguments. It retrieves the interceptable location from the compiler and it will emit the interceptor method, instead of the original call.
⚠️ This currently requires .NET 9
dotnet add package XorInterceptor
<PackageReference Include="XorInterceptor" Version="1.0.*" />
</PropertyGroup>
<!-- ... -->
<InterceptorsNamespaces>$(InterceptorsNamespaces);XorInterceptor</InterceptorsNamespaces>
<XorBuildSeed>$([System.Guid]::NewGuid().GetHashCode())</XorBuildSeed>
</PropertyGroup>
<ItemGroup>
<CompilerVisibleProperty Include="XorBuildSeed" />
<ProjectReference Include="..\XorInterceptor\XorInterceptor.csproj" OutputItemType="Analyzer" ReferenceOutputAssembly="false" />
</ItemGroup>
You can take a look at the console application included, however it is nothing more than:
using static XorInterceptor.XorEncryption;
var encryptedString = Xor( /*"Hello, World"*/);
Console.WriteLine(encryptedString);
Now each time you (re)build your project the encryption changes.
⚠️ This is of course very easy to undo, since both the encrypted data and the key are next to eachother. It is more a proof of concept.
![]()