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

Iis 为了设置网站的机器密钥,了解如何在C中使用HMACSHA256生成加密密钥#,iis,powershell,web,machinekey,Iis,Powershell,Web,Machinekey,我尝试生成机器密钥以手动更新web.config,但我需要powershell脚本来执行同样的操作。有人能帮我吗 这行吗 $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 =

我尝试生成机器密钥以手动更新web.config,但我需要powershell脚本来执行同样的操作。有人能帮我吗

这行吗

$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 '-',''

谢谢你的更新。我们需要一个与IIS中创建的密钥相同的密钥。但是看起来生成的值是字符串格式的,但是IIS中的密钥(验证密钥和解密密钥)是十六进制格式的。您能用十六进制值更新我吗(验证密钥和解密密钥需要字节?)