Base64 Encode And Decode In Java

Base64 Encoding

Base64 is an encoding method, where any data/images/audio file can be converted to binary data. And converted data can pass over the network without any data/image/audio loss

Base64 Decoding

This method is revers of base64 encoding, when received at other end, through network. Decode it and process data/image/audio files for the next specific requirement

Base64 encoding in Java

String plainText = "TestString";
byte[] encodedBytes = Base64.getEncoder().encode(plainText.getBytes(StandardCharsets.UTF_8));
String encodedString = new String(encodedBytes);
System.out.println(encodedString);

Base64 decoding in Java

byte[] decodedBytes = Base64.getDecoder().decode(encodedBytes);
String decodedString = new String(decodedBytes);
System.out.println(decodedString);
Next Recommended Reading Two Sum Array Problem In Java