Friday, 24 May 2019

base64 encode


import java.util.Base64;

class Main {
  public static void main(String[] args) {
  // Encode
String originalInput = "test input";
String encodedString = Base64.getEncoder().encodeToString(originalInput.getBytes());
System.out.println(encodedString); // Output will be: c29tZSBzdHJpbmc=

// Decode

byte[] decodedBytes = Base64.getDecoder().decode(encodedString);
String decodedString = new String(decodedBytes);
System.out.println(decodedString);
  }
}

No comments:

Post a Comment