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")


47 views0 comments

Recent Posts

See All

A proof of concept (PoC) was developed for a critical vulnerability in F5's BIG-IP networking software that could expose thousands of users to remote control. The vulnerability, tracked as CVE-2022-13

Windows Subsystem For Linux (WSL) is a tool provided by Microsoft to run Linux natively on Windows. It’s designed to be a seamless experience, essentially providing a full Linux shell that can interac

Steganography is the practice of concealing a file, message, image, or video within another file, message, image or video. This utility can conceal messages in ASCII text by appending whitespace to th