如何在Powershell中使用给定的AES密钥加密XML内容

如何在Powershell中使用给定的AES密钥加密XML内容,powershell,encryption,aes,Powershell,Encryption,Aes,我需要使用供应商API自动创建支持票证。API要求使用给定的AES密钥加密XML内容。我该怎么做?我对以下代码有问题 $xml = ' <Service> <Action>SubmitTicket</Action> <UserName>xxx@xxx.com</UserName> <Case> <Title>Title</Title> <D

我需要使用供应商API自动创建支持票证。API要求使用给定的AES密钥加密XML内容。我该怎么做?我对以下代码有问题

$xml =
'
<Service>
    <Action>SubmitTicket</Action>
    <UserName>xxx@xxx.com</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

convertfromsecurestring
参数应该是
字节
数组,而不是字符串。您可以使用
GetBytes
来实现这一点:(我假设
UTF8
编码)

指定调用中的参数名称:

$encrypted_xml = ConvertFrom-SecureString -SecureString $secureString -Key $key

也许这会引起人们的兴趣
$encrypted_xml=ConvertFrom SecureString-SecureString$SecureString-Key$Key
Good point(+1),而文档显示返回System.Array的
-Key(1..16)
$Key = [System.Text.Encoding]::UTF8.GetBytes('!QeRs6%x2RXzk6ab')
$encrypted_xml = ConvertFrom-SecureString -SecureString $secureString -Key $key