/** 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); } // ****************************************************************************************
/** 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); } // ****************************************************************************************
/** 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); }
/** 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); }
protected String encode(String user, String password) { return Base64.encodeToString((user + ":" + password).getBytes()); }
public T setBasicAuthentication(String user, String password) { header("Authorization", "Basic " + Base64.encodeToString((user + ":" + password).getBytes())); return self(); }
public T setBasicAuthentication(String user, String password) { header("Authorization", "Basic " + Base64.encodeToString((user + ":" + password).getBytes())); return self(); }
@Test public void simple_test() throws UnsupportedEncodingException { String data = "foo bar\n"; Assert.assertEquals("Zm9vIGJhcgo=", Base64.encodeToString(data.getBytes("utf-8"))); } }
public String generateToken(Request request) { String auth = request.header(Header.KEY_AUTHORIZATION); if (auth == null) return request.paramWithDefault("token", ""); byte[] token = new byte[40]; // 16+16+8 MD5.create().update(getUser(request)).asBytes(token, 0); // key BytesHolder secret = hashes.get(new BytesHolder(token, 0, 16)); long timestamp = System.currentTimeMillis() + ttl; BytesTools.toBytes(timestamp, token, 32, 8); MD5.create().update(token, 32, 8).update(secret.bytes).asBytes(token, 16); return Base64.encodeToString(token, false, true); }
key = Base64.encodeToString(SHA1.create().update(key.getBytes()).asBytes());