Loading...
Spring Security TokenBasedRememberMeServices的cookie加密

Spring专题 2015/12/18 Spring Framework , Spring Security

/**

* Calculates the digital signature to be put in the cookie. Default value is MD5

* ("username:tokenExpiryTime:password:key")

*/

protected String makeTokenSignature(long tokenExpiryTime, String username,

String password) {

String data = username + ":" + tokenExpiryTime + ":" + password + ":" + getKey();

MessageDigest digest;

try {

digest = MessageDigest.getInstance("MD5");

}

catch (NoSuchAlgorithmException e) {

throw new IllegalStateException("No MD5 algorithm available!");

}


return new String(Hex.encode(digest.digest(data.getBytes())));

}



Comments