Java Base64 encode byte array to byte array

Description

Java Base64 encode byte array to byte array

import java.util.Arrays;
import java.util.Base64;

public class Main {
  public static void main(String[] argv) throws Exception {
    byte[] array = new byte[] { 34, 35, 36, 37, 37, 37, 67, 68, 69 };

    byte[] base64ByteArray = Base64.getEncoder().encode(array);

    System.out.println(Arrays.toString(base64ByteArray));
    //from  w ww  .  j  a va  2s. co m
    array = Base64.getDecoder().decode(base64ByteArray);

    System.out.println(Arrays.toString(array));
  }
}



PreviousNext

Related