/** * Decodes Base64 data into octets * * @param base64Data Byte array containing Base64 data * @return Array containing decoded data. */ public static byte[] decodeBase64(final byte[] base64Data) { return new Base64().decode(base64Data); }
/** * Decodes a Base64 String into octets * * @param base64String String containing Base64 data * @return Array containing decoded data. * @since 1.4 */ public static byte[] decodeBase64(final String base64String) { return new Base64().decode(base64String); }
public static String base64Encode(byte[] data, boolean urlSafe) { return new Base64(0, Base64.CHUNK_SEPARATOR, urlSafe).encodeToString(data); }
public static String base64Encode(byte[] data) { return new Base64(0, Base64.CHUNK_SEPARATOR).encodeToString(data); }
public static byte[] base64Decode(String data) { return new Base64(0, Base64.CHUNK_SEPARATOR).decode(data); }
/** * Decodes Base64 data into octets * * @param base64Data Byte array containing Base64 data * @return Array containing decoded data. */ public static byte[] decodeBase64(final byte[] base64Data) { return new Base64().decode(base64Data); }
/** * Decodes a Base64 String into octets * * @param base64String String containing Base64 data * @return Array containing decoded data. * @since 1.4 */ public static byte[] decodeBase64(final String base64String) { return new Base64().decode(base64String); }
public static String base64Encode(byte[] data) { return new Base64(0, Base64.CHUNK_SEPARATOR).encodeToString(data); }
public static byte[] base64Decode(String data, boolean urlSafe) { return new Base64(0, Base64.CHUNK_SEPARATOR, urlSafe).decode(data); }
public static byte[] base64Decode(String data, boolean urlSafe) { return new Base64(0, Base64.CHUNK_SEPARATOR, urlSafe).decode(data); }
public static byte[] base64Decode(String data) { return new Base64(0, Base64.CHUNK_SEPARATOR).decode(data); }
public static String base64Encode(byte[] data, boolean urlSafe) { return new Base64(0, Base64.CHUNK_SEPARATOR, urlSafe).encodeToString(data); }
/** * Encodes binary data using the base64 algorithm, optionally chunking the output into 76 character blocks. * * @param binaryData Array containing binary data to encode. * @param isChunked if {@code true} this encoder will chunk the base64 output into 76 character blocks * @param urlSafe if {@code true} this encoder will emit - and _ instead of the usual + and / characters. * <b>Note: no padding is added when encoding using the URL-safe alphabet.</b> * @param maxResultSize The maximum result size to accept. * @return Base64-encoded data. * @throws IllegalArgumentException Thrown when the input array needs an output array bigger than maxResultSize * @since 1.4 */ public static byte[] encodeBase64(final byte[] binaryData, final boolean isChunked, final boolean urlSafe, final int maxResultSize) { if (binaryData == null || binaryData.length == 0) { return binaryData; } // Create this so can use the super-class method // Also ensures that the same roundings are performed by the ctor and the code final Base64 b64 = isChunked ? new Base64(urlSafe) : new Base64(0, CHUNK_SEPARATOR, urlSafe); final long len = b64.getEncodedLength(binaryData); if (len > maxResultSize) { throw new IllegalArgumentException("Input array too big, the output array would be bigger (" + len + ") than the specified maximum size of " + maxResultSize); } return b64.encode(binaryData); }
public static String fingerprint(byte[] data) { return new Base64(-1, new byte[0], true).encodeAsString(DigestUtils.md5(data)).toUpperCase(); }
/** * Encodes binary data using the base64 algorithm, optionally chunking the output into 76 character blocks. * * @param binaryData Array containing binary data to encode. * @param isChunked if {@code true} this encoder will chunk the base64 output into 76 character blocks * @param urlSafe if {@code true} this encoder will emit - and _ instead of the usual + and / characters. * <b>Note: no padding is added when encoding using the URL-safe alphabet.</b> * @param maxResultSize The maximum result size to accept. * @return Base64-encoded data. * @throws IllegalArgumentException Thrown when the input array needs an output array bigger than maxResultSize * @since 1.4 */ public static byte[] encodeBase64(final byte[] binaryData, final boolean isChunked, final boolean urlSafe, final int maxResultSize) { if (binaryData == null || binaryData.length == 0) { return binaryData; } // Create this so can use the super-class method // Also ensures that the same roundings are performed by the ctor and the code final Base64 b64 = isChunked ? new Base64(urlSafe) : new Base64(0, CHUNK_SEPARATOR, urlSafe); final long len = b64.getEncodedLength(binaryData); if (len > maxResultSize) { throw new IllegalArgumentException("Input array too big, the output array would be bigger (" + len + ") than the specified maximum size of " + maxResultSize); } return b64.encode(binaryData); }