gpt4 book ai didi

linux - 我如何在 linux 上对字符串进行 base64 编码,使其与 windows "Unicode.GetBytes.ToBase64String"匹配?

转载 作者:IT王子 更新时间:2023-10-29 01:20:48 30 4
gpt4 key购买 nike

<分区>

这个问题应该已经有人回答了,但是我找不到了

问题

我如何在 bash 中对字符串进行“base64 编码”,使其匹配“windows 期望的内容”,即“Unicode.GetBytes.ToBase64String”

上下文

powershell 帮助文本中有这个例子

$command='dir'
$bytes = [System.Text.Encoding]::Unicode.GetBytes($command)
$encodedCommand = [Convert]::ToBase64String($bytes)
echo $encodedCommand
powershell.exe -encodedCommand $encodedCommand

Windows 输出

编码后的输出是这样的:

ZABpAHIA

Linux 上的结果非常不同

如果我在 linux 上做同样的事情,我会得到这个:

echo "dir" | base64
ZGlyCg==

编码?

我试过使用“iconv”来转换编码,但没有成功,即相同的结果。

回显目录 |iconv -f ASCII -t UTF-8 |base64

差异

所以你可以看到两个区别:

  • 字母数字字符不同
  • 尾随“===”出现在 linux 上

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com