Created
May 1, 2013 20:03
Revisions
-
SeanPONeil created this gist
May 1, 2013 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,31 @@ private static String parseVals(String key, String val, String prefix) throws InvalidKeyException, NoSuchAlgorithmException, IOException { long ts = System.currentTimeMillis() / 1000; String[] parts = val.split("\\|"); String u_prefix = parts[0]; String u_b64 = parts[1]; String u_sig = parts[2]; String sig = Util.hmacSign(key, u_prefix + "|" + u_b64); if (!Util.hmacSign(key, sig).equals(Util.hmacSign(key, u_sig))) { return null; } if (!u_prefix.equals(prefix)) { return null; } byte[] decoded = Base64.decode(u_b64); String cookie = new String(decoded); String[] cookie_parts = cookie.split("\\|"); String username = cookie_parts[0]; String expire = cookie_parts[2]; long expire_ts = Long.parseLong(expire); if (ts >= expire_ts) { return null; } return username; }