Created
July 4, 2018 06:02
-
-
Save adrielAd/5253b700e6419073e6389d4556efa110 to your computer and use it in GitHub Desktop.
digest for calling api in fibodo
This file contains 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
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