1

I need to use a vendor API to create support tickets automatically. API requires XML content encrypted with a given AES key. How can I do this? I´m having problems with following code.

$xml =
'
<Service>
    <Action>SubmitTicket</Action>
    <UserName>[email protected]</UserName>
    <Case>
        <Title>Title</Title>
        <Description>Description</Description>
        <ProductName>ProductName</ProductName>
        <ProductVersion>1.0</ProductVersion>
        <ProductLanguage>English</ProductLanguage>
    <Purpose>Support</Purpose>
    </Case>
</Service>
'

$Key = '!QeRs6%x2RXzk6ab' (fake but similar one)

$secureString = ConvertTo-SecureString $xml -AsPlainText -Force
$encrypted_xml = ConvertFrom-SecureString $secureString -SecureString $key

I get following error.

ConvertFrom-SecureString : Cannot bind parameter 'Key'. Cannot convert value 
"!QeRs6%x2RXzk6ab" to type "System.Byte". Error: "Input string was not in a 
correct format." At C:\Users\user\Desktop\Powershell\API_Submitter.ps1:39 
char:62 + $EncryptedInfo = ConvertFrom-SecureString $secureSTring -Key $key
+ CategoryInfo: InvalidArgument: (:) [ConvertFrom-SecureString], 
ParameterBindingException + FullyQualifiedErrorId : 
CannotConvertArgumentNoMessage, 
Microsoft.PowerShell.Commands.ConvertFromSecureStringCommand
2
  • Perhaps this would be of interest. gist.github.com/ctigeek/2a56648b923d198a6e60 Commented Jan 18, 2019 at 13:07
  • $encrypted_xml = ConvertFrom-SecureString -SecureString $secureString -Key $key Commented Jan 18, 2019 at 13:22

1 Answer 1

2

The Key parameter of ConvertFrom-SecureString should be Byte array, not a string. You can use GetBytes to achieve this: (I'm assuming UTF8encoding)

$Key = [System.Text.Encoding]::UTF8.GetBytes('!QeRs6%x2RXzk6ab')

Specify the parameter names in the call:

$encrypted_xml = ConvertFrom-SecureString -SecureString $secureString -Key $key
Sign up to request clarification or add additional context in comments.

1 Comment

Good point (+1), while the docs show a -Key (1..16) which returns a System.Array

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.