Advertisement
Xyberviri

base64_encode_decode.ps1

May 27th, 2020
1,231
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #Encode file to base64
  2. $base64string = [Convert]::ToBase64String([IO.File]::ReadAllBytes($FileName))
  3.  
  4. #decode file from base64
  5. [IO.File]::WriteAllBytes($FileName, [Convert]::FromBase64String($base64string))
  6.  
  7. #Additional info
  8. # http://eddiejackson.net/wp/?author=1&paged=15
  9.  
  10.  
  11. AWS
  12. Base64 encoding
  13.  
  14. If you're using the Amazon EC2 API or a tool that does not perform base64 encoding of the user data, you must encode the user data yourself. If not, an error is logged about being unable to find script or powershell tags to execute. The following is an example that encodes using Windows PowerShell.
  15.  
  16. $UserData = [System.Convert]::ToBase64String([System.Text.Encoding]::ASCII.GetBytes($Script))
  17.  
  18. The following is an example that decodes using PowerShell.
  19.  
  20. $Script = [System.Text.Encoding]::UTF8.GetString([System.Convert]::FromBase64String($UserData))
  21.  
  22. For more information about base64 encoding, see http://tools.ietf.org/html/rfc4648
  23. .
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement