I can convert a jpeg to a base64 string using the following PowerShell command

[Convert]::ToBase64String((Get-Content -Path .\Capture.jpg -Encoding Byte)) >> capture.txt

I tried converting it back using the following

[Convert]::FromBase64String((Get-Content -Path .\capture.txt)) >> capture2.jpg

But I get a list of numbers and not a binary file. How do I convert the base64 file back to binary?

1 Answers

iRon On

If you want to handle it as a image you might want to rebuild it in memory (use it or make modifications) and then save it, like:

$Base64 = Get-Content -Raw -Path .\capture.txt
$Image = [Drawing.Bitmap]::FromStream([IO.MemoryStream][Convert]::FromBase64String($Base64))