Powershell字节数组转换为十六进制 [英] Powershell byte array to hex
问题描述
我想要获得十六进制格式的以下字节数组,以便使用aes-256-ecb解密加密的字符串. (如果您在"ConvertFrom-SecureString"函数中指定密钥参数,PowerShell将使用AES加密)
I have the following byte array that I would like to obtain hex format in order to decrypt an encrypted string using aes-256-ecb. (powershell uses AES encryption if you specify key argument in "ConvertFrom-SecureString" function)
为了对此进行检查,我使用openssl进行了验证:
In order to check this I verify by using openssl:
echo'mysecretdata'| openssl enc -d -aes-256-ecb -K 303534303438303439303939303438303938303937303435303530303530303937937537537303435435439439303439303130310a
echo 'mysecretdata' | openssl enc -d -aes-256-ecb -K 303534303438303439303939303438303938303937303435303530303530303937303537303435303439303439303130310a
十六进制字符串太长 无效的十六进制键值
hex string is too long invalid hex key value
我想念什么?
谢谢.
推荐答案
您可以在每个单独的字节上使用X2
格式字符串以获取其十六进制表示形式,然后使用-join
运算符来连接字符串:>
You can use the X2
format string on each individual byte to get it's hex representation, then use the -join
operator to concatenate the strings:
$bytes = 0,54,0,48,0,49,0,99,0,48,0,98,0,97,0,45,0,50,0,50,0,97,0,57,0,45,0,49,0,49,0,101
$hexString = ($bytes|ForEach-Object ToString X2) -join ''
(如果这是您的实际密钥,由于它是公共知识,您可能要避免再次使用它;-))
(If that's your actual key, you might want to refrain from ever using it again, now that it's public knowledge ;-) )
这篇关于Powershell字节数组转换为十六进制的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!