Skip to content

Instantly share code, notes, and snippets.

@beetsolutions
Last active December 13, 2016 12:11
Show Gist options
  • Save beetsolutions/c539b0a64ef064930bd3bcaf8187760c to your computer and use it in GitHub Desktop.
Save beetsolutions/c539b0a64ef064930bd3bcaf8187760c to your computer and use it in GitHub Desktop.
Get Certificate pinning sha with Square OKHTTP 3
// Make sure this does not run on the main thread.
String hostname = "yourdomain.com";
CertificatePinner certificatePinner = new CertificatePinner.Builder()
.add(hostname, "sha256/AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=")
.build();
OkHttpClient client = new OkHttpClient.Builder()
.certificatePinner(certificatePinner)
.build();
Request request = new Request.Builder()
.url("https://" + hostname)
.build();
try {
client.newCall(request).execute();
} catch (IOException e) {
e.printStackTrace();
// Inspect the error details for the correct sha
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment