Mentalis.org Security Library documentation

DataProtectionCryptoServiceProvider.ProtectData Method (ProtectionType, Byte[], Int32, Int32, Byte[])

Encrypts data according to a specified protection type.

[Visual Basic]
Overloads Public Function ProtectData( _
   ByVal type As ProtectionType, _
   ByVal data As Byte(), _
   ByVal offset As Integer, _
   ByVal size As Integer, _
   ByVal entropy As Byte() _
) As Byte()
[C#]
public byte[] ProtectData(
   ProtectionType type,
   byte[] data,
   int offset,
   int size,
   byte[] entropy
);

Parameters

type
One of the ProtectionType values.
data
The data to encrypt.
offset
The zero-based position in the data parameter at which to begin encrypting.
size
The number of bytes to encrypt.
entropy
Additional entropy to use during the encyption process. This parameter can be set to null.

Return Value

An array of encrypted bytes.

Remarks

The number of the returned bytes will be larger than the number of input bytes.

Exceptions

Exception TypeCondition
ArgumentNullExceptiondata is a null reference (Nothing in Visual Basic).
ArgumentExceptionThe specified offset or size exceeds the size of buffer.
CryptographicExceptionAn error occurs during the encryption process. Under some circumstances, Microsoft cryptographic service providers may not allow encryption when used in France. This may occur on down-level platforms such as Windows 98 and Windows NT 4.0, depending on the system's configuration and the version of the CSPs.

See Also

DataProtectionCryptoServiceProvider Class | Org.Mentalis.Security.Cryptography Namespace | DataProtectionCryptoServiceProvider.ProtectData Overload List