<PackageReference Include="System.Security.Cryptography.ProtectedData" Version="10.0.0" />

ProtectedData

public static class ProtectedData
Provides methods for encrypting and decrypting data. This class cannot be inherited.
public static byte[] Protect(byte[] userData, byte[] optionalEntropy, DataProtectionScope scope)

Encrypts the data in a specified byte array and returns a byte array that contains the encrypted data.

public static byte[] Protect(ReadOnlySpan<byte> userData, DataProtectionScope scope, ReadOnlySpan<byte> optionalEntropy = default)

Encrypts the data in a specified byte span and returns a byte array that contains the encrypted data.

public static int Protect(ReadOnlySpan<byte> userData, DataProtectionScope scope, Span<byte> destination, ReadOnlySpan<byte> optionalEntropy = default)

Encrypts the data in a specified buffer and writes the encrypted data to a destination buffer.

public static bool TryProtect(ReadOnlySpan<byte> userData, DataProtectionScope scope, Span<byte> destination, out int bytesWritten, ReadOnlySpan<byte> optionalEntropy = default)

Encrypts the data in a specified buffer and writes the encrypted data to a destination buffer.

public static bool TryUnprotect(ReadOnlySpan<byte> encryptedData, DataProtectionScope scope, Span<byte> destination, out int bytesWritten, ReadOnlySpan<byte> optionalEntropy = default)

Decrypts the data in a specified buffer and writes the decrypted data to a destination buffer.

public static byte[] Unprotect(byte[] encryptedData, byte[] optionalEntropy, DataProtectionScope scope)

Decrypts the data in a specified byte array and returns a byte array that contains the decrypted data.

public static byte[] Unprotect(ReadOnlySpan<byte> encryptedData, DataProtectionScope scope, ReadOnlySpan<byte> optionalEntropy = default)

Decrypts the data in a specified byte array and returns a byte array that contains the decrypted data.

public static int Unprotect(ReadOnlySpan<byte> encryptedData, DataProtectionScope scope, Span<byte> destination, ReadOnlySpan<byte> optionalEntropy = default)

Decrypts the data in a specified buffer and writes the decrypted data to a destination buffer.