Decode Base64

About Base64

What is Base64 encoding?

Base64 is a binary-to-text encoding scheme that represents binary data in an ASCII string format. It's commonly used to encode binary data for transmission over text-based systems.

Why use Base64 encoding?

Base64 encoding is useful when you need to transmit binary data over media that are designed to deal with text. This encoding helps ensure that the data remains intact without modification during transport.

Base64 in Bash

# Encoding
echo -n "Hello, World!" | base64
# Output: SGVsbG8sIFdvcmxkIQ==

# Decoding
echo "SGVsbG8sIFdvcmxkIQ==" | base64 -d
# Output: Hello, World!
			

Base64 in Javascript

// Encoding
let encoded = btoa("Hello, World!");
console.log(encoded);
// Output: SGVsbG8sIFdvcmxkIQ==

// Decoding
let decoded = atob("SGVsbG8sIFdvcmxkIQ==");
console.log(decoded);
// Output: Hello, World!

			

Base64 in Go

package main
import (
	"encoding/base64"
	"fmt"
)
func main() {
	// Encoding
	encoded := base64.StdEncoding.EncodeToString([]byte("Hello, World!"))
	fmt.Println(encoded)
	// Output: SGVsbG8sIFdvcmxkIQ==

	// Decoding
	decoded, _ := base64.StdEncoding.DecodeString("SGVsbG8sIFdvcmxkIQ==")
	fmt.Println(string(decoded))
	// Output: Hello, World!
}
			

Base64 in PHP

// Encoding
$encoded = base64_encode("Hello, World!");
echo $encoded ."\n";
// Output: SGVsbG8sIFdvcmxkIQ==

// Decoding
$decoded = base64_decode("SGVsbG8sIFdvcmxkIQ==");
echo $decoded . "\n";
// Output: Hello, World!