我找到了一些资源(包括Convert base64 string to file,这里实际上是重复的,因为它是我用来构建它的资源之一),但我似乎无法让它工作。
我有以下代码(大致 - 显然它已被剥离),我可以根据评论验证该过程的大部分步骤。
$pic = Get-Content 'testpic.png'
# $pic looks like a binary dump.
$picBytes = [System.Text.Encoding]::Unicode.GetBytes($pic)
$ $picBytes is an array of bytes. Quite spammy.
$picEncoded = [Convert]::ToBase64String($picBytes)
# $picEncoded is indeed a Base64 string. Halfway there!
$picDecoded = [Convert]::FromBase64String($picEncoded)
# Also an array of bytes. I'm assuming they're right for now...
$outFile = "pic.png"
[IO.File]::WriteAllBytes($outFile,$picDecoded)
# but I get no output file and no error?
我在这里想念什么?对于它的价值,我愿意看看其他解决方案 - 但 Base64 有点重要(因为我将数据存储在脚本中。)