Base64 Encode Converter

Base64 encode

Base64 encoding is the process of converting binary data into a set of printable ASCII characters. It is commonly used to represent binary data in a safe and readable format.

Here's how you can perform Base64 encoding in various programming languages:

JavaScript
// Assuming you have binary data in a string or a Uint8Array
const data = "Hello World!"; // Example data to encode

// Encoding the data to Base64
const base64Encoded = btoa(data);
console.log(base64Encoded); // Output: "SGVsbG8gV29ybGQh"

Python
import base64

# Assuming you have binary data in bytes
data = b"Hello World!"  # Example data to encode

# Encoding the data to Base64
base64_encoded = base64.b64encode(data).decode('utf-8')
print(base64_encoded)  # Output: "SGVsbG8gV29ybGQh"

Java
import java.util.Base64;

public class Main {
    public static void main(String[] args) {
        // Assuming you have binary data in a byte array
        byte[] data = "Hello World!".getBytes(); // Example data to encode

        // Encoding the data to Base64
        String base64Encoded = Base64.getEncoder().encodeToString(data);
        System.out.println(base64Encoded); // Output: "SGVsbG8gV29ybGQh"
    }
}

Note that in each programming language, the btoa() function in JavaScript, base64.b64encode() function in Python, and Base64.getEncoder().encodeToString() method in Java are used to perform the Base64 encoding. The encoded output should be a string that represents the binary data in a Base64 format.

resources