Convert base64 string to file

I am trying to convert base64 strings back to source files. The application where I am trying to export these files from will only allow me to export base64 strings. This export returns a base64 string and file type.

How can I convert these lines back to source files? I tried such things, but I don’t think this will work with different types of files?

[System.Text.Encoding]::UTF8.GetString([System.Convert]::FromBase64String($file)) | Out-File C:\ID\document.$($extension) 

Can someone give me some ideas on how to do this?

+5
source share
1 answer

The FromBase64String() method FromBase64String() base64 encoded string to an array of bytes. All you have to do is write an array of bytes to a file:

 $b64 = 'AAAAAA...' $filename = 'C:\path\to\file' $bytes = [Convert]::FromBase64String($b64) [IO.File]::WriteAllBytes($filename, $bytes) 
+10
source

Source: https://habr.com/ru/post/1242756/


All Articles