public static SecretKey generateKeyAsMD5(String key) { return generateKey(MD5.create().update(key).asBytes()); }
/** Decodes a BASE64 encoded <code>String</code>. All illegal characters will be ignored and can handle both strings with * and without line separators.<br> * <b>Note!</b> It can be up to about 2x the speed to call <code>decode(str.toCharArray())</code> instead. That * will create a temporary array though. This version will use <code>str.charAt(i)</code> to iterate the string. * @param str The source string. <code>null</code> or length 0 will return an empty array. * @return The decoded array of bytes. May be of length 0. Will be <code>null</code> if the legal characters * (including '=') isn't divideable by 4. (I.e. definitely corrupted). */ public final static byte[] decode(String str) { return decode(str, false); }
/** Decodes a BASE64 encoded char array that is known to be resonably well formatted. The method is about twice as * fast as {@link #decode(char[])}. The preconditions are:<br> * + The array must have a line length of 76 chars OR no line separators at all (one line).<br> * + Line separator must be "\r\n", as specified in RFC 2045 * + The array must not contain illegal characters within the encoded string<br> * + The array CAN have illegal characters at the beginning and end, those will be dealt with appropriately.<br> * @param sArr The source array. Length 0 will return an empty array. <code>null</code> will throw an exception. * @return The decoded array of bytes. May be of length 0. */ public final static byte[] decodeFast(char[] sArr) { return decodeFast(sArr, false); }
/** Encodes a raw byte array into a BASE64 <code>String</code> representation i accordance with RFC 2045. * @param sArr The bytes to convert. If <code>null</code> or length 0 an empty array will be returned. * @param lineSep Optional "\r\n" after 76 characters, unless end of file.<br> * No line separator will be in breach of RFC 2045 which specifies max 76 per line but will be a * little faster. * @return A BASE64 encoded array. Never <code>null</code>. */ public final static String encodeToString(byte[] sArr, boolean lineSep) { return encodeToString(sArr, lineSep, false); } // ****************************************************************************************
/** * @return hash as hex string */ public String asString() { return toHexString(asBytes()); }
public static MD5 create() { return new MD5(); } }
/** Encodes a raw byte array into a BASE64 <code>char[]</code> representation i accordance with RFC 2045. * @param sArr The bytes to convert. If <code>null</code> or length 0 an empty array will be returned. * @param lineSep Optional "\r\n" after 76 characters, unless end of file.<br> * No line separator will be in breach of RFC 2045 which specifies max 76 per line but will be a * little faster. * @return A BASE64 encoded array. Never <code>null</code>. */ public final static char[] encodeToChar(byte[] sArr, boolean lineSep) { return encodeToChar(sArr, lineSep, false); }
/** Encodes a raw byte array into a BASE64 <code>byte[]</code> representation i accordance with RFC 2045. * @param sArr The bytes to convert. If <code>null</code> or length 0 an empty array will be returned. * @param lineSep Optional "\r\n" after 76 characters, unless end of file.<br> * No line separator will be in breach of RFC 2045 which specifies max 76 per line but will be a * little faster. * @return A BASE64 encoded array. Never <code>null</code>. */ public final static byte[] encodeToByte(byte[] sArr, boolean lineSep) { return encodeToByte(sArr, lineSep, false); } // ****************************************************************************************
public static SecretKey generateKeyAsMD5(String key) { return generateKey(MD5.create().update(key).asBytes()); }
/** Encodes a raw byte array into a BASE64 <code>String</code> representation i accordance with RFC 2045. * @param sArr The bytes to convert. If <code>null</code> or length 0 an empty array will be returned. * @param lineSep Optional "\r\n" after 76 characters, unless end of file.<br> * No line separator will be in breach of RFC 2045 which specifies max 76 per line but will be a * little faster. * @return A BASE64 encoded array. Never <code>null</code>. */ public final static String encodeToString(byte[] sArr, boolean lineSep) { return encodeToString(sArr, lineSep, false); } // ****************************************************************************************
/** Decodes a BASE64 encoded string that is known to be resonably well formatted. The method is about twice as * fast as {@link #decode(String)}. The preconditions are:<br> * + The array must have a line length of 76 chars OR no line separators at all (one line).<br> * + Line separator must be "\r\n", as specified in RFC 2045 * + The array must not contain illegal characters within the encoded string<br> * + The array CAN have illegal characters at the beginning and end, those will be dealt with appropriately.<br> * @param s The source string. Length 0 will return an empty array. <code>null</code> will throw an exception. * @return The decoded array of bytes. May be of length 0. */ public final static byte[] decodeFast(String s) { return decodeFast(s, false); }
/** Decodes a BASE64 encoded <code>String</code>. All illegal characters will be ignored and can handle both strings with * and without line separators.<br> * <b>Note!</b> It can be up to about 2x the speed to call <code>decode(str.toCharArray())</code> instead. That * will create a temporary array though. This version will use <code>str.charAt(i)</code> to iterate the string. * @param str The source string. <code>null</code> or length 0 will return an empty array. * @return The decoded array of bytes. May be of length 0. Will be <code>null</code> if the legal characters * (including '=') isn't divideable by 4. (I.e. definitely corrupted). */ public final static byte[] decode(String str) { return decode(str, false); }
/** Encodes a raw byte array into a BASE64 <code>String</code> representation i accordance with RFC 2045. * @param sArr The bytes to convert. If <code>null</code> or length 0 an empty array will be returned. * No line separator will be in breach of RFC 2045 which specifies max 76 per line but will be a * little faster. * @return A BASE64 encoded array. Never <code>null</code>. */ public final static String encodeToString(byte[] sArr) { return encodeToString(sArr, false, false); }
/** Decodes a BASE64 encoded char array that is known to be resonably well formatted. The method is about twice as * fast as {@link #decode(char[])}. The preconditions are:<br> * + The array must have a line length of 76 chars OR no line separators at all (one line).<br> * + Line separator must be "\r\n", as specified in RFC 2045 * + The array must not contain illegal characters within the encoded string<br> * + The array CAN have illegal characters at the beginning and end, those will be dealt with appropriately.<br> * @param sArr The source array. Length 0 will return an empty array. <code>null</code> will throw an exception. * @return The decoded array of bytes. May be of length 0. */ public final static byte[] decodeFast(char[] sArr) { return decodeFast(sArr, false); }
/** Decodes a BASE64 encoded byte array. All illegal characters will be ignored and can handle both arrays with * and without line separators. * @param sArr The source array. Length 0 will return an empty array. <code>null</code> will throw an exception. * @return The decoded array of bytes. May be of length 0. Will be <code>null</code> if the legal characters * (including '=') isn't divideable by 4. (I.e. definitely corrupted). */ public final static byte[] decode(byte[] sArr) { return decode(sArr, false); }
/** Decodes a BASE64 encoded byte array that is known to be resonably well formatted. The method is about twice as * fast as {@link #decode(byte[])}. The preconditions are:<br> * + The array must have a line length of 76 chars OR no line separators at all (one line).<br> * + Line separator must be "\r\n", as specified in RFC 2045 * + The array must not contain illegal characters within the encoded string<br> * + The array CAN have illegal characters at the beginning and end, those will be dealt with appropriately.<br> * @param sArr The source array. Length 0 will return an empty array. <code>null</code> will throw an exception. * @return The decoded array of bytes. May be of length 0. */ public final static byte[] decodeFast(byte[] sArr) { return decodeFast(sArr, false); }
/** Decodes a BASE64 encoded char array. All illegal characters will be ignored and can handle both arrays with * and without line separators. * @param sArr The source array. <code>null</code> or length 0 will return an empty array. * @return The decoded array of bytes. May be of length 0. Will be <code>null</code> if the legal characters * (including '=') isn't divideable by 4. (I.e. definitely corrupted). */ public final static byte[] decode(char[] sArr) { return decode(sArr, false); }