RSA-шифрование powershell, предоставляя модуль и экспоненту - PullRequest
0 голосов
/ 22 февраля 2019

Я пытался выполнить шифрование RSA в своем скрипте powershell, указав модуль и экспоненту, и развернул его в модуле автоматизации Azure.

function Get-EncryptedString($certPass) 
{
    Write-Output "Getting Encrypted String."    

    $rsa = New-Object System.Security.Cryptography.RSACryptoServiceProvider
    $parameters = New-Object System.Security.Cryptography.RSAParameters
    $parameters.Modulus = $script:secretKey.Key.N
    $parameters.Exponent = $script:secretKey.Key.E
    $rsa.ImportParameters($parameters)    
    $byteData = [System.Text.Encoding]::Unicode.GetBytes($certPass)
    $encryptedData = $rsa.Encrypt($byteData, $true)
    $result = [System.Convert]::ToBase64String($encryptedData)

    Write-Output "Encrypted String retrieved: $result"

    return $result
}

Когда я выполняю то же самое, я получаю следующееошибка

перехвачено исключение: System.Management.Automation.MethodInvocationException: исключение, вызывающее «ImportParameters» с аргументом «1»: «Неверные данные.

» --->System.Security.Cryptography.CryptographicException: неверные данные.

в System.Security.Cryptography.CryptographicException.ThrowCryptographicException (Int32 ч)

в System.Security.Cryptography.Utille_Imp_HP, Int32 keyNumber, CspProviderFlags флаги, объект cspObject, SafeKeyHandle & hKey)

в System.Security.Cryptography.RSACryptoServiceProvider.ImportParameters (параметры RSAParameters)

в CallSite, CallSite.TargetObject)

--- Конец внутренней трассировки стека исключений ---

в System.Management.Automation.ExceptionHandlingOps.CheckActionPreference (FunctionContext funcContext, исключение)

в System.Management.Automation.Interpreter.ActionCallInstruction`2.Run (кадр InterpretedFrame)

в системе..Automation.Interpreter.EnterTryCatchFinallyInstruction.Run (кадр InterpretedFrame)

в System.Management.Automation.Interpreter.EnterTryCatchFinallyInstruction.Run (кадр InterpretedFrame)

...