Skip to content

Instantly share code, notes, and snippets.

@iAnatoly
Created August 4, 2016 17:55
Show Gist options
  • Select an option

  • Save iAnatoly/254220f98f2627c484ab32b76c813756 to your computer and use it in GitHub Desktop.

Select an option

Save iAnatoly/254220f98f2627c484ab32b76c813756 to your computer and use it in GitHub Desktop.
One-liners encoding and decoding Base64 in powershell
[System.Convert]::ToBase64String([System.Text.Encoding]::UTF8.GetBytes("SecretMessage"))
[System.Text.Encoding]::UTF8.GetString([System.Convert]::FromBase64String("U2VjcmV0TWVzc2FnZQ=="))
@em-daniil-terentyev
Copy link
Copy Markdown

Thanks! :)

@B-Art
Copy link
Copy Markdown

B-Art commented Aug 13, 2024

BASE64 is NOT an encryption code. It is more kind of DEcompression.
By limitting the amount of usable characters to 64 characters (use only 6 bits instead of 8 bits).
You are now able to transform any binairy value into a readable Characterset.
You will need about 33% extra space. (any 6 bits binairy info will use 8 bits)
The length of "SecretMessage no way." is 21 characters and is transfored into "U2VjcmV0TWVzc2FnZSBubyB3YXku" which is 28 characters.
Every 4 characters in BASE64 will be transformed into 3 normal bytes.

@RokeJulianLockhart
Copy link
Copy Markdown

RokeJulianLockhart commented Oct 16, 2024

#gistcomment-5152729

@B-Art, have you context? I ask because I have not observed anyone purporting that base-64 encodement is a method of encryption.

L1-L2

By the way, if any readers are interested in this, stackoverflow.com/revisions/55680423/4 explains well.

@zerbaliy3v
Copy link
Copy Markdown

zerbaliy3v commented Mar 31, 2026

from file:
$b64 = Get-Content -Path ".\b64.txt" -raw ;[System.Text.Encoding]::UTF8.GetString([System.Convert]::FromBase64String($b64))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment