zoukankan      html  css  js  c++  java
  • Asp.net中machineKey的生成和作用

    machineKey生成代码:

    代码
    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配置:

    代码
    xml version="1.0"?>

    <configuration>

    <system.web>

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

    system.web>

    configuration>
     

    machineKey作用:

    1)在forms authentication tickets认证时加密与解密,防止被篡改。

    2)ViewState加密与解密,防止篡改。

    3)使用进程外session(out-of-process session)时,对会话状态标识进行验证。

    作者:Olar Tan
    出处:http://www.cnblogs.com/olartan
    ♪:没有做不到的 只有偷懒而错过的 ♪

  • 相关阅读:
    js,js中使用正则表达式
    web开发中文件下载
    EL表达式
    Servlet Filter
    压缩文件 乱码问题(转载)
    MFC CopyDirectory
    SaveFileDialog
    Create Window
    CDateTimeCtrl 设置时间
    键值表
  • 原文地址:https://www.cnblogs.com/olartan/p/1880665.html
Copyright © 2011-2022 走看看