com.tukeof.common.util.Base64Util Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of common-core Show documentation
Show all versions of common-core Show documentation
a common and useful pure java library
The newest version!
package com.tukeof.common.util;
import java.nio.charset.StandardCharsets;
import java.util.Base64;
/**
* Create by tuke on 2019-02-15
*/
public class Base64Util {
private static final Base64.Encoder Base64_ENCODER = Base64.getEncoder();
private static final Base64.Decoder Base64_DECODER = Base64.getDecoder();
public static byte[] encodeBase64(byte[] input) {
return Base64_ENCODER.encode(input);
}
public static byte[] encodeBase64(String input) {
return encodeBase64(input.getBytes(StandardCharsets.ISO_8859_1));
}
public static String encodeBase64ToString(byte[] input) {
return new String(encodeBase64(input), StandardCharsets.ISO_8859_1);
}
public static String encodeBase64ToString(String input) {
return new String(encodeBase64(input), StandardCharsets.ISO_8859_1);
}
// ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ----
/**
* @param input any bytes
* @return ascii bytes
* @see Base64.Decoder#decode(String)
*/
public static byte[] decodeBase64(byte[] input) {
return Base64_DECODER.decode(input);
}
public static byte[] decodeBase64(String input) {
return decodeBase64(input.getBytes(StandardCharsets.ISO_8859_1));
}
public static String decodeBase64ToString(byte[] input) {
return new String(decodeBase64(input), StandardCharsets.ISO_8859_1);
}
public static String decodeBase64ToString(String input) {
return new String(decodeBase64(input), StandardCharsets.ISO_8859_1);
}
}