Generation and function of machineKey in Asp.net

Source: Internet
Author: User

Machinekey Generation Code:

Code

 validationKey = CreateKey(20); 

decryptionKey = CreateKey(24);

protected string CreateKey(int len)

{

byte[] bytes = new byte[len];

new RNGCryptoServiceProvider().GetBytes(bytes);

StringBuilder sb = new StringBuilder();

for(int i = 0; i < bytes.Length; i++)

{

sb.Append(string.Format("{0:X2}",bytes[i]));

}

return sb.ToString();

}

Web. config Configuration:

Code

 
 xml version="1.0"?> 

<configuration>

<system.web>

<machineKey validationKey="3FF1E929BC0534950B0920A7B59FA698BD02DFE8" decryptionKey="280450BB36319B474C996B506A95AEDF9B51211B1D2B7A77" decryption="3DES" validation="SHA1"/>

system.web>

configuration>
 

Machinekey:

1) encryption and decryption during Forms authentication tickets authentication to prevent tampering.

2) viewstate encryption and decryption to prevent tampering.

3) when an out-of-process session is used, the session Status identifier is verified.

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.