Protect() public static method

public static Protect ( byte userData, byte optionalEntropy, DataProtectionScope scope ) : byte[]
userData byte
optionalEntropy byte
scope DataProtectionScope
return byte[]
Example #1
0
 /// <summary>
 ///     Protects the specified data by applying an encryption algorthim specified by the <see cref="DataProtectionScope" />.
 /// </summary>
 /// <param name="unencryptedData">The unencrypted data.</param>
 /// <param name="optionalEntropy">The optional entropy.</param>
 /// <param name="scope">The scope.</param>
 /// <returns>The encrypted data in a byte array.</returns>
 /// <exception cref="ArgumentNullException">The encryptedData parameter is null.</exception>
 /// <exception cref="CryptographicException">The cryptographic protection failed.</exception>
 /// <exception cref="PlatformNotSupportedException">The operating system does not support this method.</exception>
 /// <exception cref="OutOfMemoryException">The system ran out of memory while encrypting the data.</exception>
 public static byte[] Protect(byte[] unencryptedData, string optionalEntropy, DataProtectionScope scope)
 {
     byte[] salt = (!string.IsNullOrEmpty(optionalEntropy)) ? Encoding.Unicode.GetBytes(optionalEntropy) : null;
     byte[] data = ProtectedData.Protect(unencryptedData, salt, scope);
     return(data);
 }
Example #2
0
 protected override byte[] ProviderProtect(byte[] userData)
 {
     // Delegate to ProtectedData
     return(ProtectedData.Protect(userData, GetHashedPurpose(), Scope));
 }