2017-08-07 47 views
0

我們遷移一個在Windows Server 2008  到服務器  2016年 現在我在這個腳本得到一個錯誤:簽名密碼,並獲得價值回

cls 
$key = (2,3,56,34,254,222,1,1,2,23,42,54,33,233,1,34,2,7,6,5,35,43,6,6,6,6,6,6,31,33,60,23) 
$pass = Read-Host -AsSecureString 
$securepass = $pass | ConvertFrom-SecureString -Key $key 
$bytes = [byte[]][char[]]$securepass    

$csp = New-Object System.Security.Cryptography.CspParameters 
$csp.KeyContainerName = "SuperSecretProcessOnMachine" 
$csp.Flags = $csp.Flags -bor [System.Security.Cryptography.CspProviderFlags]::UseMachineKeyStore 
$rsa = New-Object System.Security.Cryptography.RSACryptoServiceProvider -ArgumentList 5120,$csp 
$rsa.PersistKeyInCsp = $true 

$encrypted = $rsa.Encrypt($bytes,$true) 
$encrypted | Export-Clixml 'C:\Temp\encrypted_ysastaginpro_PRE.txt' -Force 

錯誤代碼:

 
New-Object : Exception calling ".ctor" with "2" argument(s): "Object already 
exists." 
At C:\Program Files\Staging\MESDI\Create_PSW_File_Poly.ps1:13 char:10 
+ ...  $rsa = New-Object System.Security.Cryptography.RSACryptoServiceP ... 
+     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 
    + CategoryInfo   : InvalidOperation: (:) [New-Object], MethodInvocationException 
    + FullyQualifiedErrorId : ConstructorInvokedThrowException,Microsoft.PowerShell.Commands.NewObjectCommand 

Exception calling "Encrypt" with "2" argument(s): "Bad Length." 
At C:\Program Files\Staging\MESDI\Create_PSW_File_Poly.ps1:18 char:3 
+   $encrypted = $rsa.Encrypt($bytes,$true) 
+   ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 
    + CategoryInfo   : NotSpecified: (:) [], MethodInvocationException 
    + FullyQualifiedErrorId : CryptographicException 

回答

0

我找到了解決方案。 以管理員身份運行PS腳本。