Sample code for 30+ languages & platforms
PowerBuilder

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 PowerBuilder Downloads

PowerBuilder
integer li_rc
integer li_Success
oleobject loo_PrivKey
string ls_Thumbprint

li_Success = 0

//  Load a private key to export.
loo_PrivKey = create oleobject
li_rc = loo_PrivKey.ConnectToNewObject("Chilkat.PrivateKey")
if li_rc < 0 then
    destroy loo_PrivKey
    MessageBox("Error","Connecting to COM object failed")
    return
end if
li_Success = loo_PrivKey.LoadPemFile("qa_data/private.pem")
if li_Success = 0 then
    Write-Debug loo_PrivKey.LastErrorText
    destroy loo_PrivKey
    return
end if

//  Compute the RFC 7638 thumbprint of the key's public portion using the named hash algorithm.
//  Supported values include "sha256", "sha1", "md5", and others.
ls_Thumbprint = loo_PrivKey.GetJwkThumbprint("sha256")
if loo_PrivKey.LastMethodSuccess = 0 then
    Write-Debug loo_PrivKey.LastErrorText
    destroy loo_PrivKey
    return
end if

Write-Debug "JWK thumbprint: " + ls_Thumbprint


destroy loo_PrivKey