MachineKeyValidation 枚举

定义

指定 ASP.NET 用于 Forms 身份验证和验证视图状态数据,以及进程外会话状态标识的哈希算法。Specifies the hashing algorithm that ASP.NET uses for forms authentication and for validating view state data, and for out-of-process session state identification.

public enum class MachineKeyValidation
public enum MachineKeyValidation
type MachineKeyValidation = 
Public Enum MachineKeyValidation
继承
MachineKeyValidation

字段

AES 3

指明 ASP.NET 使用 AES (Rijndael) 加密算法。Specifies that ASP.NET uses the AES (Rijndael) encryption algorithm. 如果要在 Web 应用程序中加密视图状态,请选择此选项。Choose this option if you want to encrypt view state in your Web application.

如果选择此选项,则 DecryptionKey 属性将用于加密和解密,HMACSHA1 哈希算法将与 ValidationKey 属性一起用于验证。If you choose this option, the DecryptionKey property will be used for encryption and decryption, and the HMACSHA1 hash algorithm will be used with the ValidationKey property for validation.

Custom 7

指明 ASP.NET 使用自定义的哈希算法。Specifies that ASP.NET uses a custom hashing algorithm. 自定义哈希算法可以在派生自 KeyedHashAlgorithm 的任何类中实现。The custom hashing algorithm can be implemented in any class that derives from KeyedHashAlgorithm.

自定义算法通常在 machineKey 元素的 validation 属性中以声明方式指定,格式为 alg:\`algorithm_nameThe custom algorithm is typically specified declaratively in the validation attribute of the machineKey element, in the format alg:\`*algorithm_name*. 有关如何在代码中指定自定义算法的信息,请参阅 ValidationAlgorithm 属性。For information about how to specify a custom algorithm in code, see the ValidationAlgorithm property.

HMACSHA256 4

指定 ASP.NET 使用 HMACSHA256 哈希算法,该算法是生成 256 位哈希代码的 SHA2 哈希算法。Specifies that ASP.NET uses the HMACSHA256 hashing algorithm, which is an SHA2 hashing algorithm that generates a 256-bit hash code. 这是默认值。This is the default value.

HMACSHA384 5

指定 ASP.NET 使用 HMACSHA384 哈希算法,该算法是生成 384 位哈希代码的 SHA2 哈希算法。Specifies that ASP.NET uses the HMACSHA384 hashing algorithm, which is an SHA2 hashing algorithm that generates a 384-bit hash code. 此选项适用于需要的安全性高于 HMACSHA256 算法所提供的安全性的应用程序。This option is available for applications that require stronger security than provided by the HMACSHA256 algorithm..

HMACSHA512 6

指定 ASP.NET 使用 HMACSHA512 哈希算法,该算法是生成 512 位哈希代码的 SHA2 哈希算法。Specifies that ASP.NET uses the HMACSHA512 hashing algorithm, which is an SHA2 hashing algorithm that generates a 512-bit hash code. 此选项适用于需要的安全性高于 >HMACSHA384 算法所提供的安全性的应用程序。This option is available for applications that require stronger security than provided by the >HMACSHA384 algorithm.

MD5 0

指定 ASP.NET 使用 Message Digest 5 (MD5) 哈希算法,该算法是生成 128 位哈希代码的哈希算法。Specifies that ASP.NET uses the Message Digest 5 (MD5) hashing algorithm, which is a hashing algorithm that generates a 128-bit hash value. 这是一个旧值,只有在需要与早期版本的 ASP.NET 兼容时才应选择该值。This is a legacy value that should be selected only if compatibility with earlier versions of ASP.NET is required.

SHA1 1

指定 ASP.NET 使用 HMACSHA1 哈希算法,该算法是生成 160 位哈希值的哈希算法。Specifies that ASP.NET uses the HMACSHA1 hash algorithm, which is a hashing algorithm that generates a 160-bit hash value. 这是一个旧值,只有在需要与早期版本的 ASP.NET 兼容时才应选择该值。This is a legacy value that should be selected only if compatibility with earlier versions of ASP.NET is required.

TripleDES 2

指定 ASP.NET 使用 TripleDES (3DES) 加密算法,该算法仅在指定视图状态已加密时使用。Specifies that ASP.NET uses the TripleDES (3DES) encryption algorithm, which is an encryption algorithm that is used only if you specify that view state is encrypted. 这是一个旧值,只有在需要与早期版本的 ASP.NET 兼容时才应选择该值。This is a legacy value that should be selected only if compatibility with earlier versions of ASP.NET is required..

示例

下面的代码示例演示如何使用MachineKeyValidation枚举。The following code example shows how to use the MachineKeyValidation enumeration. 在此示例中configSection , 是的MachineKeySection实例。此代码示例是为MachineKeySection类提供的更大示例的一部分。In the example, configSection is an instance of MachineKeySection.This code example is part of a larger example provided for the MachineKeySection class.

// Set Validation property.
configSection.Validation = MachineKeyValidation.SHA1;
' Set Validation value.
configSection.Validation = MachineKeyValidation.SHA1

注解

ASP.NET 使用基于哈希的消息身份验证代码 (HMAC) 来帮助检测用于窗体身份验证或视图状态的数据是否已被篡改。ASP.NET uses a hash-based message authentication code (HMAC) to help detect whether data that is used for forms authentication or view state has been tampered with. 创建视图状态内容时, 将生成 HMAC, 并在后续请求中检查 HMAC。The HMAC is generated when view state content is created, and the HMAC is checked on subsequent requests. HMAC 有助于 ASP.NET 确定是否有人更改了服务器和客户端之间发送的数据, 但数据在通过 Internet 传播的任何人都可以读取数据, 除非该数据也已加密。The HMAC helps ASP.NET determine whether someone has changed data that is sent between the server and the client, but the data can be read by anyone as it travels through the Internet unless it is also encrypted. 默认情况下, 视图状态已验证但未加密。By default, view state is validated but not encrypted. 有关详细信息,请参阅 ViewStateEncryptionModeRegisterRequiresViewStateEncryptionFor more information, see ViewStateEncryptionMode and RegisterRequiresViewStateEncryption.

MachineKeyValidation枚举可用于指定 ASP.NET 用来创建 HMAC 的算法。The MachineKeyValidation enumeration lets you specify the algorithm that ASP.NET uses to create the HMAC. 默认值为 HMACSHA256The default value is HMACSHA256. ASP.NET 将ValidationKey属性的值与所选算法一起使用以生成 HMAC。ASP.NET uses the value of the ValidationKey property with the selected algorithm to generate the HMAC.

适用于

另请参阅