复制代码代码如下 :
import com.google.common.base.charsets;
import com.google.common.hash.hashing;
import java.util.date;
import org.apache.commons.lang.time.fastdateformat;
/**
*
* @Author Charles
*/
공개 계급 토큰 틸트 {
개인 정적 최종 문자열 privatekey = "fdas34ljfr 好 sja@#8 $%dfkl; js & 4*daklfjsdl; akfjsa342";
public static string getToken (문자열 암호, 문자열 날짜) {
return hashing.md5 (). newhasher ().
putstring (비밀번호, charsets.utf_8).
Putstring (privatekey, charsets.utf_8).
putstring (날짜, charsets.utf_8) .hash (). tostring ();
}
public static string getToken (문자열 비밀번호, 날짜 날짜) {
return hashing.md5 (). newhasher ().
putstring (비밀번호, charsets.utf_8).
Putstring (privatekey, charsets.utf_8).
putstring (getDate (날짜), charsets.utf_8) .hash (). tostring ();
}
public static string getToken (String Password) {
return hashing.md5 (). newhasher ().
putstring (비밀번호, charsets.utf_8).
putstring (privatekey, charsets.utf_8) .putString (getDate (), charsets.utf_8) .hash (). toString ();
}
public static boolean validToken (문자열 토큰, 문자열 비밀번호) {
문자열 확인 = getToken (비밀번호);
if (확인 .Equals (토큰)) {
진실을 반환하십시오.
} 또 다른 {
거짓을 반환합니다.
}
}
public static string getDate () {
날짜 날짜 = 새 날짜 (System.CurrentTimeMillis ());
return fastdateformat.getinstance ( "yyyymmddhh"). 형식 (날짜);
}
public static string getDate (지금 날짜) {
FastDateFormat.getInstance ( "yyyymmddhh"). 형식 (지금);
}
public static string getnexthour (지금 날짜) {
날짜 = 새 날짜 (now.gettime ()+60*60*1000);
return fastdateformat.getinstance ( "yyyymmddhh"). 형식 (날짜);
}
}