Online Base64 Encoding / Decoding

Decode and Encode using base64, generic base64 encoding and decoding system, convert text to base64 and vice versa.

Base64 Encoding / Decoding code snippets

Get Base64 Encoding / Decoding code snippets for PHP, JAVA, Python, C# and Visual Basic, just copy and paste the code in your project

// Base64 Encoding
$encoded = base64_encode($input);

// Base64 Decoding
$decoded = base64_decode($encoded);
import java.util.Base64;

// Base64 Encoding
String encoded = Base64.getEncoder().encodeToString(input.getBytes());

// Base64 Decoding
byte[] decoded = Base64.getDecoder().decode(encoded);
String decodedString = new String(decoded);
import base64

# Base64 Encoding
encoded = base64.b64encode(input.encode()).decode()

# Base64 Decoding
decoded = base64.b64decode(encoded).decode()
using System;

// Base64 Encoding
string encoded = Convert.ToBase64String(System.Text.Encoding.UTF8.GetBytes(input));

// Base64 Decoding
byte[] decoded = Convert.FromBase64String(encoded);
string decodedString = System.Text.Encoding.UTF8.GetString(decoded);
Imports System

' Base64 Encoding
Dim encoded As String = Convert.ToBase64String(System.Text.Encoding.UTF8.GetBytes(input))

' Base64 Decoding
Dim decodedBytes As Byte() = Convert.FromBase64String(encoded)
Dim decodedString As String = System.Text.Encoding.UTF8.GetString(decodedBytes)

Base64 is a binary-to-text encoding scheme that represents binary data in an ASCII string format. It is commonly used to encode binary data, such as images, audio files, or cryptographic keys, into a format that can be safely transmitted over text-based channels, such as email or HTTP headers. Base64 encoding achieves this by converting each set of three bytes from the input data into four ASCII characters from a predefined set of 64 characters (hence the name "Base64"). This encoding process increases the size of the data by approximately 33%, as it uses six bits of each ASCII character to represent the binary data. Despite the increased size, Base64 encoding ensures that binary data remains intact during transmission, as it only utilizes characters that are safe for text-based communication.

When encoding data using Base64, the input binary data is divided into 6-bit chunks, which are then converted into their corresponding Base64 characters. Each chunk corresponds to an ASCII character in the Base64 alphabet. If the length of the input data is not divisible by three, padding characters ('=') are added to the end to ensure that the input data can be properly decoded later. Decoding works in reverse, where each set of four Base64 characters is converted back into its original binary representation. During decoding, padding characters are used to determine the length of the original input data. Base64 encoding and decoding algorithms are widely implemented in various programming languages and are fundamental for encoding binary data for transmission across text-based communication channels while ensuring data integrity and compatibility.

Have a question? Send me a message !

Contact me