@Override public String encode(byte[] aData) { return new String(Base64.encode(aData)); }
public static boolean isBase64( String isValidString ) { return isArrayByteBase64(isValidString.getBytes()); }
public static boolean isArrayByteBase64( byte[] arrayOctect ) { int length = arrayOctect.length; if (length == 0) { // shouldn't a 0 length array be valid base64 data? // return false; return true; } for (int i=0; i < length; i++) { if ( !Base64.isBase64(arrayOctect[i]) ) return false; } return true; }
/** * Parse the username from the specified authorization credentials. * If none can be found, return <code>null</code>. * * @param authorization Authorization credentials from this request */ protected String parseUsername(String authorization) { if (authorization == null) return (null); if (!authorization.toLowerCase(Locale.ENGLISH).startsWith("basic ")) return (null); authorization = authorization.substring(6).trim(); // Decode and parse the authorization credentials String unencoded = new String(Base64.decode(authorization.getBytes(Charset.defaultCharset()))); int colon = unencoded.indexOf(':'); if (colon < 0) return (null); String username = unencoded.substring(0, colon); // String password = unencoded.substring(colon + 1).trim(); return (username); }
/** * Parse the password from the specified authorization credentials. * If none can be found, return <code>null</code>. * * @param authorization Authorization credentials from this request */ protected char[] parsePassword(String authorization) { if (authorization == null) return (null); if (!authorization.toLowerCase(Locale.ENGLISH).startsWith("basic ")) return (null); authorization = authorization.substring(6).trim(); // Decode and parse the authorization credentials String unencoded = new String(Base64.decode(authorization.getBytes(Charset.defaultCharset()))); int colon = unencoded.indexOf(':'); if (colon < 0) return (null); // String username = unencoded.substring(0, colon).trim(); char[] password = unencoded.substring(colon + 1).toCharArray(); return (password); }
Base64.decode(authorizationBC, authorizationCC);
private String getWebSocketAccept(String key) { synchronized (sha1Helper) { sha1Helper.reset(); sha1Helper.update(key.getBytes(B2CConverter.ISO_8859_1)); return Base64.encode(sha1Helper.digest(WS_ACCEPT)); } }
public static boolean isBase64( String isValidString ) { return isArrayByteBase64(isValidString.getBytes()); }
public static boolean isArrayByteBase64( byte[] arrayOctect ) { int length = arrayOctect.length; if (length == 0) { // shouldn't a 0 length array be valid base64 data? // return false; return true; } for (int i=0; i < length; i++) { if ( !Base64.isBase64(arrayOctect[i]) ) return false; } return true; }
Base64.decode(authorizationBC, authorizationCC);
private String getWebSocketAccept(String key) throws ServletException { MessageDigest sha1Helper = sha1Helpers.poll(); if (sha1Helper == null) { try { sha1Helper = MessageDigest.getInstance("SHA1"); } catch (NoSuchAlgorithmException e) { throw new ServletException(e); } } sha1Helper.reset(); sha1Helper.update(key.getBytes(B2CConverter.ISO_8859_1)); String result = Base64.encode(sha1Helper.digest(WS_ACCEPT)); sha1Helpers.add(sha1Helper); return result; }
public static boolean isBase64( String isValidString ) { return isArrayByteBase64(isValidString.getBytes()); }
public static boolean isArrayByteBase64( byte[] arrayOctect ) { int length = arrayOctect.length; if (length == 0) { // shouldn't a 0 length array be valid base64 data? // return false; return true; } for (int i=0; i < length; i++) { if ( !Base64.isBase64(arrayOctect[i]) ) return false; } return true; }
Base64.decode(authorizationBC, authorizationCC);
private String getWebSocketAccept(String key) throws ServletException { MessageDigest sha1Helper = sha1Helpers.poll(); if (sha1Helper == null) { try { sha1Helper = MessageDigest.getInstance("SHA1"); } catch (NoSuchAlgorithmException e) { throw new ServletException(e); } } sha1Helper.reset(); sha1Helper.update(key.getBytes(EncodingToCharset.ISO_8859_1)); String result = new String(Base64.encode(sha1Helper.digest(WS_ACCEPT))); sha1Helpers.add(sha1Helper); return result; }