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?
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))
$Image.Save("<path>\Image2.jpg")
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With