System.Security.Cryptography.ProtectedData.Protect C# (CSharp) Method

Protect() public static method

public static Protect ( byte userData, byte optionalEntropy, DataProtectionScope scope ) : byte[]
userData byte
optionalEntropy byte
scope DataProtectionScope
return byte[]
        public static byte[] Protect(byte[] userData, byte[] optionalEntropy, DataProtectionScope scope)
        {
            if (userData == null)
                throw new ArgumentNullException(nameof(userData));

            return ProtectOrUnprotect(userData, optionalEntropy, scope, protect: true);
        }

Same methods

ProtectedData::Protect ( byte userData, byte optionalEntropy, System scope ) : byte[]

Usage Example

Beispiel #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);
 }
All Usage Examples Of System.Security.Cryptography.ProtectedData::Protect