PowerShell | Encoding & Decoding (Base64)

PowerShell provides an easy method for Base64 encoding and decoding.


Encoding:

$pass="STENGE.info"
$encodePass=[System.Text.Encoding]::Unicode.GetBytes($pass)
$encodeStr=[Convert]::ToBase64String($encodePass)
$encodeStr

The result is this base64 encoded text:

UwBUAEUATgBHAEUALgBpAG4AZgBvAA==

Decoding:

$encodeStr="UwBUAEUATgBHAEUALgBpAG4AZgBvAA=="
$bytesData=[System.Convert]::FromBase64String($encodeStr)
$decodeValue=[System.Text.Encoding]::Unicode.GetString($bytesData)
$decodeValue

The result:

STENGE.info


And if you want to convert a file, it should look something like :

$fileName = "C:\usr\key.txt"
$fileContent = get-content $fileName
$fileContentBytes = [System.Text.Encoding]::Unicode.GetBytes($fileContent)
$fileContentEncoded = [System.Convert]::ToBase64String($fileContentBytes)
$fileContentEncoded | set-content ($fileName + ".b64")


54 views0 comments

Recent Posts

See All

Here I will show you a command that will help you to transfer files faster between computers, it's very useful when you need to transfer a large amount of files. You can do it to transfer to others ha

Malicious executables often attempt to hide their behavior and evade detection. By doing so, they present anomalies and suspicious patterns. Pestudio is a free tool that allows you to perform an initi

Do you want to build by yourself a LAN server right on your Windows computer? Here you have some steps to do it works. #1) Go to openspeedtest.com; #2) Click on DOWNLOAD link; #3) Download and install