Created
May 1, 2013 20:03
-
-
Save SeanPONeil/5497929 to your computer and use it in GitHub Desktop.
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 characters
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; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment