locked
RSACryptoServiceProvider error with Windows Server 2016 RRS feed

  • Question

  • 

    We migrate one Windows Server 2008 to server 2016.

    Now I get an error at this script:

    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

    The error message is:

    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

    I hope somebody can help me, thx Horst


    Thanks Horst MOSS 2007 Farm; MOSS 2010 Farm; TFS 2010; TFS 2013; IIS 7.5


    • Edited by wuwu Monday, August 7, 2017 10:59 AM Add error message
    Monday, August 7, 2017 10:57 AM

Answers

  • I found the solution.

    Run the PS script as adminstrator

    

    Thanks Horst MOSS 2007 Farm; MOSS 2010 Farm; TFS 2010; TFS 2013; IIS 7.5

    • Marked as answer by wuwu Tuesday, August 8, 2017 6:03 AM
    Tuesday, August 8, 2017 6:03 AM

All replies