01
Pinned.
The garbage collector never moves a sensitive buffer, so it never leaves a stale copy of a key behind.
Pinned, pooled .NET buffers that zero their memory on dispose. For keys, passwords and anything else you don't want left behind on the heap.
dotnet add package NCode.Buffers
// A pinned, pooled 32-byte key, zeroed when keyOwner is disposed.
using var keyOwner = BufferFactory.Rent(32, isSensitive: true, out Span<byte> key);
RandomNumberGenerator.Fill(key);
01
The garbage collector never moves a sensitive buffer, so it never leaves a stale copy of a key behind.
02
Disposing a buffer overwrites all of it, in a way the JIT cannot optimize away.
03
Buffers are reused, and each one is zeroed before another caller can rent it.