如何生成machineKey
2015-10-20 15:44
330 查看
>cmd
>PowerShell_ISE
新建
![](http://img.blog.csdn.net/20151020154746959?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQv/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center)
把上面的代码粘贴到里面
运行脚本
命令行输入Generate-MachineKey
回车
ok
>PowerShell_ISE
新建
# 生成一个可复制并粘贴到 Web.config 文件中的 <machineKey> 元素。 function Generate-MachineKey { [CmdletBinding()] param ( [ValidateSet("AES", "DES", "3DES")] [string]$decryptionAlgorithm = 'AES', [ValidateSet("MD5", "SHA1", "HMACSHA256", "HMACSHA384", "HMACSHA512")] [string]$validationAlgorithm = 'HMACSHA256' ) process { function BinaryToHex { [CmdLetBinding()] param($bytes) process { $builder = new-object System.Text.StringBuilder foreach ($b in $bytes) { $builder = $builder.AppendFormat([System.Globalization.CultureInfo]::InvariantCulture, "{0:X2}", $b) } $builder } } switch ($decryptionAlgorithm) { "AES" { $decryptionObject = new-object System.Security.Cryptography.AesCryptoServiceProvider } "DES" { $decryptionObject = new-object System.Security.Cryptography.DESCryptoServiceProvider } "3DES" { $decryptionObject = new-object System.Security.Cryptography.TripleDESCryptoServiceProvider } } $decryptionObject.GenerateKey() $decryptionKey = BinaryToHex($decryptionObject.Key) $decryptionObject.Dispose() switch ($validationAlgorithm) { "MD5" { $validationObject = new-object System.Security.Cryptography.HMACMD5 } "SHA1" { $validationObject = new-object System.Security.Cryptography.HMACSHA1 } "HMACSHA256" { $validationObject = new-object System.Security.Cryptography.HMACSHA256 } "HMACSHA385" { $validationObject = new-object System.Security.Cryptography.HMACSHA384 } "HMACSHA512" { $validationObject = new-object System.Security.Cryptography.HMACSHA512 } } $validationKey = BinaryToHex($validationObject.Key) $validationObject.Dispose() [string]::Format([System.Globalization.CultureInfo]::InvariantCulture, "<machineKey decryption=`"{0}`" decryptionKey=`"{1}`" validation=`"{2}`" validationKey=`"{3}`" />", $decryptionAlgorithm.ToUpperInvariant(), $decryptionKey, $validationAlgorithm.ToUpperInvariant(), $validationKey) } }
把上面的代码粘贴到里面
运行脚本
命令行输入Generate-MachineKey
回车
ok
相关文章推荐
- SpringMVC+ajaxFileUpload 异步上传
- 第四章、供应链视角
- C#之Winform中treeview控件绑定数据库
- RPAD的使用--对字符串使用指定的字符进行填充
- SharePoint 2013 IT Professional--Convert License Type
- 正则
- java Relative Path and absolute
- ipvsadm命令参数
- 广度优先入门程序
- sql随机抽取数据
- could not find the main class,program will exit
- GlusterFS常用命令小结
- chkconfig
- Selenium 的基本了解以及Selenium IDE插件的知识点
- Maven学习
- 分支限界法(算法分析与设计)
- 【DP】permu
- jQuery获取Select选择的Text和 Value(转)
- Java中关于OOM的场景及解决方法
- hadoop自定义输出文件名