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
The
Key
parameter ofConvertFrom-SecureString
should beByte
array, not a string. You can useGetBytes
to achieve this: (I'm assumingUTF8
encoding)Specify the parameter names in the call: