Skip to content

Instantly share code, notes, and snippets.

@phstudy
Created December 3, 2018 09:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save phstudy/af1c9c9859808eaf06adec60af5c4072 to your computer and use it in GitHub Desktop.
Save phstudy/af1c9c9859808eaf06adec60af5c4072 to your computer and use it in GitHub Desktop.
calculate SAPISIDDASH
import com.google.common.hash.Hashing;
import java.nio.charset.Charset;
public class GoogleTokenUtils {
public static String calcSapiSidDash(long ts, String sapiSid, String origin) {
return String.format("%d_%s", ts, calcHash(ts, sapiSid, origin));
}
public static String calcSapiSidDash(String sapiSid, String origin) {
long ts = System.currentTimeMillis();
return calcSapiSidDash(ts, sapiSid, origin);
}
private static String calcHash(long ts, String sapiSid, String origin) {
String plain = String.format("%d %s %s", ts, sapiSid, origin);
return Hashing.sha1().hashString(plain, Charset.defaultCharset()).toString();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment