使用powershell生成机器密钥
我正在尝试生成机器密钥,以便在几台机器之间共享,在谷歌快速搜索后我发现了这个使用powershell生成机器密钥,powershell,Powershell,我正在尝试生成机器密钥,以便在几台机器之间共享,在谷歌快速搜索后我发现了这个 我复制了代码并将其另存为.ps1扩展,我认为这是powershell扩展 开式电源外壳 移动到文件的位置 运行脚本 PS E:/生成机器钥匙-验证sha1 它运行正常,但不输出键。有什么原因吗?我在Powershell做错什么了吗 谢谢,脚本包含一个函数,因此您必须首先加载脚本,然后运行该函数才能使其工作 首先,我们必须加载文件,我称我的ps1为“MachineKey”,所以我就是这样加载它的 PS E:\> .
谢谢,脚本包含一个函数,因此您必须首先加载脚本,然后运行该函数才能使其工作 首先,我们必须加载文件,我称我的ps1为“MachineKey”,所以我就是这样加载它的
PS E:\> . .\MachineKey.ps1
一旦我加载了文件,如果我想运行名为“Generate MachineKey”的函数,我必须在之后输入这个
PS E:\> Generate-MachineKey -validationAlgorithm SHA1
它的方式比我想象的要简单:不需要保存.ps1文件,只需粘贴脚本并运行它。我在本地电脑上,以管理员身份赢得8.1分 以管理员身份打开PowerShell 从以下位置粘贴脚本:
Windows PowerShell
版权所有(C)2014年微软公司。版权所有。
PS C:\Users\JM>#生成一个可以复制并粘贴到Web.config文件中的元素。
PS C:\Users\JM>函数生成MachineKey{
>>[CmdletBinding()]
>>param(
>>[验证集(“AES”、“DES”、“3DES”)]
>>[string]$decryptionAlgorithm='AES',
>>[验证集(“MD5”、“SHA1”、“HMACSHA256”、“HMACSHA384”、“HMACSHA512”)]
>>[string]$validationAlgorithm='HMACSHA256'
>> )
>>过程{
>>函数二进制十六进制{
>>[CmdLetBinding()]
>>参数($bytes)
>>过程{
>>$builder=新对象System.Text.StringBuilder
>>foreach($b,单位为$bytes){
>>$builder=$builder.AppendFormat([System.Globalization.CultureInfo]::不变量文化,“{0:X2}”,$b)
>> }
>>$builder
>> }
>> }
>>交换机($decryptionAlgorithm){
>>“AES”{$decryptionObject=new object System.Security.Cryptography.AesCryptoServiceProvider}
>>“DES”{$decryptionObject=new object System.Security.Cryptography.DESCryptoServiceProvider}
>>“3DES”{$decryptionObject=new object System.Security.Cryptography.TripleDecryptoServiceProvider}
>> }
>>$decryptionObject.GenerateKey()
>>$decryptionKey=BinaryToHex($decryptionObject.Key)
>>$decryptionObject.Dispose()
>>交换机($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=binarytochex($validationObject.Key)
>>$validationObject.Dispose()
>>[string]::格式([System.Globalization.CultureInfo]::不变量文化,
>> "",
>>$decryptionAlgorithm.ToUpperInvariant(),$decryptionKey,
>>$ValidationGorithm.ToUpperInvariant(),$validationKey)
>> }
>> }
>>
在下一行键入此命令
PS C:\Users\JM> Generate-MachineKey
<machineKey decryption="AES" decryptionKey="xxxxxxxxxxxxxxxxxxxx" validation="HMACSHA256" validationKey="xxxxxxxxxxxxxxxxx" />
PS C:\Users\JM>Generate MachineKey
谢谢,我不熟悉powershell。首先,我必须在管理模式下打开powershell控制台。然后,执行Set ExecutionPolicy Unrestricted。再次在管理模式下关闭并打开另一个PS控制台。注册并执行Bluecakes所说的函数,最后执行Set ExecutionPolicy Restricted。这是因为默认情况下脚本执行被阻止。是否可以使用ValidationGorithm=AES生成MachineKey?
PS C:\Users\JM> Generate-MachineKey
<machineKey decryption="AES" decryptionKey="xxxxxxxxxxxxxxxxxxxx" validation="HMACSHA256" validationKey="xxxxxxxxxxxxxxxxx" />