Skip to content
Base64

Base64

Base64 encode / decode (+ UTF-16-LE)

Base64 converts bytes into printable ASCII characters. It is an encoding rather than encryption: decoding requires no key. Standard Base64 uses + and /; URL-safe Base64 replaces them with - and _ so the result can be placed more safely in URLs and tokens.

import base64

raw_bytes = b"data"
encoded_bytes = base64.b64encode(raw_bytes)
encoded_text = encoded_bytes.decode()

decoded_bytes = base64.b64decode(encoded_text)
decoded_text = decoded_bytes.decode()

urlsafe_bytes = base64.urlsafe_b64encode(raw_bytes)
urlsafe_text = urlsafe_bytes.decode()

powershell_command = "whoami"
powershell_bytes = powershell_command.encode("utf-16-le")
powershell_encoded_bytes = base64.b64encode(powershell_bytes)
powershell_encoded = powershell_encoded_bytes.decode()

b64encode() and b64decode() operate on bytes. .decode() converts the resulting ASCII bytes into a Python string. PowerShell’s encoded-command input expects the original command as UTF-16 little-endian bytes before Base64 encoding.

Find by: base64, encode, decode, b64encode, b64decode, utf-16-le, powershell, urlsafe, bytes, string · Source: PG/Monster