/** * Tests a given String to see if it contains only valid characters within the Base64 alphabet. Currently the method * treats whitespace as valid. * * @param base64 String to test * @return <code>true</code> if all characters in the String are valid characters in the Base64 alphabet or if the * String is empty; <code>false</code>, otherwise */ public static boolean isBase64(String base64) { return null == base64 ? false : isBase64(Strings.getBytesUtf8(base64)); }
/** * Tests a given byte array to see if it contains only valid characters within the Base64 alphabet. Currently the * method treats whitespace as valid. * * @param base64Bytes byte array to test * @return <code>true</code> if all bytes are valid characters in the Base64 alphabet or if the byte array is empty; * <code>false</code>, otherwise */ public static boolean isBase64(byte[] base64Bytes) { if (null == base64Bytes) { return false; } for (int i = 0; i < base64Bytes.length; i++) { if (!isBase64(base64Bytes[i]) && !isWhiteSpace(base64Bytes[i])) { return false; } } return true; }
protected String[] decodeRememberMeTokens(Cookie cookie) { String encodedTokenString = cookie.getValue(); for (int j = 0; j < encodedTokenString.length() % 4; j++) { encodedTokenString = encodedTokenString + "="; } if(!Base64.isBase64(encodedTokenString)) { log.debug("The remember-me cookie is not a valid base64 string"); return null; } String decodedTokenString = Base64.decode(encodedTokenString); String[] tokens = Strings.split(decodedTokenString, ':'); if(tokens.length != 3){ return null; } return tokens; }
if(!Base64.isBase64(encoded)) { log.debug("The encoded token '{}' is not a valid base64 string",encoded); return false;