ProtectedData.TryProtect Method
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Encrypts the data in a specified buffer and writes the encrypted data to a destination buffer.
public static bool TryProtect(ReadOnlySpan<byte> userData, System.Security.Cryptography.DataProtectionScope scope, Span<byte> destination, out int bytesWritten, ReadOnlySpan<byte> optionalEntropy = default);
static member TryProtect : ReadOnlySpan<byte> * System.Security.Cryptography.DataProtectionScope * Span<byte> * int * ReadOnlySpan<byte> -> bool
Public Shared Function TryProtect (userData As ReadOnlySpan(Of Byte), scope As DataProtectionScope, destination As Span(Of Byte), ByRef bytesWritten As Integer, Optional optionalEntropy As ReadOnlySpan(Of Byte) = Nothing) As Boolean
Parameters
- userData
- ReadOnlySpan<Byte>
A buffer that contains data to encrypt.
- scope
- DataProtectionScope
One of the enumeration values that specifies the scope of encryption.
- bytesWritten
- Int32
When this method returns, contains the number of bytes written to destination.
- optionalEntropy
- ReadOnlySpan<Byte>
An optional additional buffer used to increase the complexity of the encryption, or empty for no additional complexity.
Returns
true if destination was large enough to receive the decrypted data; otherwise, false.
Exceptions
The buffer in destination is too small to hold the encrypted data.
The encryption failed.
The operating system does not support this method.
The system ran out of memory while encrypting the data.
The operating system is not Windows.