Skip to content

Instantly share code, notes, and snippets.

@adrielAd
Created July 4, 2018 06:02
Show Gist options
  • Save adrielAd/5253b700e6419073e6389d4556efa110 to your computer and use it in GitHub Desktop.
Save adrielAd/5253b700e6419073e6389d4556efa110 to your computer and use it in GitHub Desktop.
digest for calling api in fibodo
public static String getDigest(String url){
StringBuilder stringBuilder = new StringBuilder();
String username = String.format("username=\"%1$s\"", BuildConfig.username);
String realm = String.format("realm=\"%1$s\"", BuildConfig.realm);
long nonceTime = Calendar.getInstance(TimeZone.getTimeZone("UTC")).getTimeInMillis()/1000;
String nonce = String.format("nonce=\"%1$d\"", nonceTime);
String uri = String.format("uri=\"%1$s\"", BuildConfig.api_path + BuildConfig.version + url);
String HA1 = md5(BuildConfig.username + ":" + BuildConfig.realm + ":" + BuildConfig.password);
String HA2 = md5("POST:"+ url);
String response = String.format("response=\"%1$s\"", md5(HA1 + ":" + nonceTime + ":" +HA2));
stringBuilder.append(username);
stringBuilder.append(",");
stringBuilder.append(realm);
stringBuilder.append(",");
stringBuilder.append(nonce);
stringBuilder.append(",");
stringBuilder.append(uri);
stringBuilder.append(",");
stringBuilder.append(response);
return stringBuilder.toString();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment