Sample code for 30+ languages & platforms
PowerBuilder

Compute a Public Key's JWK Thumbprint

Demonstrates the Chilkat PublicKey.GetJwkThumbprint method, which returns the RFC 7638 JWK thumbprint for the public key. 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 canonical hash of the key's public parameters — a compact fingerprint that identifies the key regardless of formatting. It is the standard way to derive a stable key ID (kid) and to check whether two representations are the same key. Chilkat builds the required canonical JSON, hashes it with the named algorithm, and returns the result.

Chilkat PowerBuilder Downloads

PowerBuilder
integer li_rc
integer li_Success
oleobject loo_PubKey
string ls_Thumbprint

li_Success = 0

//  Load a public key to export.  LoadFromFile inspects the content, so it accepts DER, PEM, XML,
//  JWK, and other supported representations.
loo_PubKey = create oleobject
li_rc = loo_PubKey.ConnectToNewObject("Chilkat.PublicKey")
if li_rc < 0 then
    destroy loo_PubKey
    MessageBox("Error","Connecting to COM object failed")
    return
end if
li_Success = loo_PubKey.LoadFromFile("qa_data/public.pem")
if li_Success = 0 then
    Write-Debug loo_PubKey.LastErrorText
    destroy loo_PubKey
    return
end if

//  Compute the RFC 7638 JWK thumbprint of the public key using the named hash algorithm.  Common
//  values include "sha256".
ls_Thumbprint = loo_PubKey.GetJwkThumbprint("sha256")
if loo_PubKey.LastMethodSuccess = 0 then
    Write-Debug loo_PubKey.LastErrorText
    destroy loo_PubKey
    return
end if

Write-Debug "JWK thumbprint: " + ls_Thumbprint


destroy loo_PubKey