public static Protect ( byte userData, byte optionalEntropy, DataProtectionScope scope ) : byte[] | ||
userData | byte | |
optionalEntropy | byte | |
scope | DataProtectionScope | |
리턴 | 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);
}
ProtectedData::Protect ( byte userData, byte optionalEntropy, System scope ) : byte[] |
/// <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); }