Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
MachineKey Class
Collapse the table of content
Expand the table of content

MachineKey Class

Provides a way to encrypt or hash data (or both) by using the same algorithms and key values that are used for ASP.NET forms authentication and view state.

System.Object
  System.Web.Security.MachineKey

Namespace:  System.Web.Security
Assembly:  System.Web (in System.Web.dll)

[<AbstractClass>]
[<Sealed>]
type MachineKey =  class end

The MachineKey type exposes the following members.

  NameDescription
Public methodStatic memberDecodeDecodes and/or validates data that has been encrypted or provided with a hash-based message authentication code (HMAC).
Public methodStatic memberEncodeEncrypts data and/or appends a hash-based message authentication code (HMAC).
Top

ExceptionCondition
ArgumentNullException

The data to encrypt, hash, decrypt, or validate does not exist

The MachineKey class provides methods that expose the hashing and encryption logic that ASP.NET provides. For information about which encryption and hashing algorithms ASP.NET uses, and the key values that it uses with them, see machineKey Element (ASP.NET Settings Schema).

The following example shows how to encrypt, hash, decrypt, and validate a string. The code accepts a string that you enter, encrypts the data and adds a hash value to it using one call to the Encode(Byte[], MachineKeyProtection) method, and then displays the encrypted data. The code then decrypts and validates the encrypted data in one call to the Decode(String, MachineKeyProtection) method, and displays the decrypted data in another label. The Encode(Byte[], MachineKeyProtection) and Decode(String, MachineKeyProtection) methods accept a parameter that specifies whether they should encrypt or decrypt, hash or validate, or do both. In this example they do both.

No code example is currently available or this language may not be supported.

.NET Framework

Supported in: 4

Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Community Additions

ADD
Show:
© 2015 Microsoft