Base64 Converter

General

What is base64Why use base64Base64 vs. base32

Encoder

String to base64Image to base64File to base64PDF to base64Hex to base64

Decoder

Base64 to stringBase64 to imageBase64 to PDFBase64 to Hex

Developer

Base64 in javascriptBase64 in pythonBase64 in goBase64 in PHPBase64 in javaBase64 in ruby

Tools

Validate Base64

Base64 Converter

Base64 Online Encoder & Decoder

Base64 in Java

In Java, Base64 is a standard class provided in the java.util package that allows developers to encode and decode binary data using the Base64 encoding scheme. Base64 encoding is commonly used for encoding binary data, such as images or audio files, into a text format that can be easily transferred over the internet. The Base64 class in Java provides a simple and efficient way to perform encoding and decoding operations in Java applications.
Encoding
To encode a string to base64 in Java, you can use the Base64 class from the java.util package. The Base64 class provides two static methods for encoding: getEncoder() and getMimeEncoder(). getEncoder() returns a basic encoder that maps 3-byte chunks to 4-byte base64 characters. getMimeEncoder() returns an encoder that's more suited for MIME-like applications, where line breaks need to be inserted every 76 characters.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 import java.util.Base64; public class Base64Encoder { public static void main(String[] args) { String message = "Hello world!"; // Get basic encoder Base64.Encoder encoder = Base64.getEncoder(); // Encode message to base64 String encodedMessage = encoder.encodeToString(message.getBytes()); System.out.println("Encoded message: " + encodedMessage); // output: SGVsbG8gd29ybGQh } }
Decoding
To decode a Base64-encoded string in Java, you can use the Base64 class from the java.util package. The Base64 class provides a static getDecoder() method that returns a Base64.Decoder instance, which you can use to decode a Base64-encoded string. Here's an example code snippet that shows how to decode a Base64-encoded string in Java:
1 2 3 4 5 6 7 8 9 10 import java.util.Base64; public class Base64DecoderExample { public static void main(String[] args) { String encodedString = "SGVsbG8gd29ybGQh"; // Base64-encoded "Hello world!" byte[] decodedBytes = Base64.getDecoder().decode(encodedString); String decodedString = new String(decodedBytes); System.out.println(decodedString); // Output: Hello world! } }
When To Use Java Base64 getMimeEncoder vs. getEncoder
In Java, the Base64 class provides two methods for encoding data: getEncoder() and getMimeEncoder(). The main difference between the two is the output format of the encoded data.
The getEncoder() method encodes data in the default format, which is a basic MIME type with no line breaks. This is the most commonly used method for encoding binary data to base64 in Java.
The getMimeEncoder() method, on the other hand, produces MIME-compatible output with line breaks every 76 characters. This method is more appropriate when the encoded data is expected to be used in MIME messages or other protocols that require specific line break formatting.
In general, it is recommended to use getEncoder() unless there is a specific need for MIME compatibility or line breaks in the encoded data.

General

What is base64Why use base64Base64 vs. base32

Misc

Privacy PolicyTerms & Conditions

Base64 Converter

© 2023 Base64 Online Converter. All rights reserved