2017-08-07 13 views
0

は、我々はサーバーに  2008 1台のWindowsサーバーを移行  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スクリプトを管理者として実行します。

関連する問題