Android™
Android™
Compute a Private Key's JWK Thumbprint
See more Private Key Examples
Demonstrates the Chilkat PrivateKey.GetJwkThumbprint method, which computes the RFC 7638 thumbprint of the key's public portion using a named hash algorithm. The only argument is the hash algorithm (for example sha256).
Note: The file paths are relative to the application's current working directory. Absolute paths may also be used. Supply the paths appropriate to your own environment.
Background: A JWK thumbprint is a stable, canonical hash of a key's public parameters — a short fingerprint that identifies the key independent of formatting. It is widely used as a key ID (
kid) in JWK Sets and JWTs, and for comparing whether two representations are the same key. Because it hashes only the public portion, it can be shared freely even though it is computed here from the private key.Chilkat Android™ Downloads
// Important: Don't forget to include the call to System.loadLibrary
// as shown at the bottom of this code sample.
package com.test;
import android.app.Activity;
import com.chilkatsoft.*;
import android.widget.TextView;
import android.os.Bundle;
public class SimpleActivity extends Activity {
private static final String TAG = "Chilkat";
// Called when the activity is first created.
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
boolean success = false;
// Load a private key to export.
CkPrivateKey privKey = new CkPrivateKey();
success = privKey.LoadPemFile("qa_data/private.pem");
if (success == false) {
Log.i(TAG, privKey.lastErrorText());
return;
}
// Compute the RFC 7638 thumbprint of the key's public portion using the named hash algorithm.
// Supported values include "sha256", "sha1", "md5", and others.
String thumbprint = privKey.getJwkThumbprint("sha256");
if (privKey.get_LastMethodSuccess() == false) {
Log.i(TAG, privKey.lastErrorText());
return;
}
Log.i(TAG, "JWK thumbprint: " + thumbprint);
}
static {
System.loadLibrary("chilkat");
// Note: If the incorrect library name is passed to System.loadLibrary,
// then you will see the following error message at application startup:
//"The application <your-application-name> has stopped unexpectedly. Please try again."
}
}