top of page

PowerShell | Encoding & Decoding (Base64)

Writer's picture: Diniz MartinsDiniz Martins

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


85 views0 comments

Recent Posts

See All

IPSec vs. TLS

When it comes to securing data over networks, IPSec (Internet Protocol Security) and TLS (Transport Layer Security) are two of the most...

VyOS Basic Configuration

VyOS is an open-source network operating system that provides software-based network routing, firewall, and VPN services. It is designed...

Comentários


Programming and IT solutions guide on STENGE.info blog
Cybersecurity and Networking tutorials on STENGE.info
IT infrastructure solutions and technology tutorials
STENGE.info logo - Tech Blog for IT Solutions and Tutorials
bottom of page