为网站设置机器密钥如何在C#中使用HMACSHA256生成加密密钥

时间:2013-09-30 05:58:05

标签: iis powershell web machinekey

我尝试生成机器密钥以手动更新web.config,但我需要PowerShell脚本来执行相同的操作。任何人都可以帮助我吗?

enter image description here

1 个答案:

答案 0 :(得分:1)

这有用吗?

$key = "2012"
$string = "End of the world is nowhere near us."
$sha256 = New-Object System.Security.Cryptography.HMACSHA256
$sha256.key = [Text.Encoding]::ASCII.GetBytes($key)
$signature = $sha256.ComputeHash([Text.Encoding]::ASCII.GetBytes($string))
$hash = ([Convert]::ToBase64String($signature)) -replace '-',''