Sample code for 30+ languages & platforms
DataFlex

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

DataFlex
Use ChilkatAx-win32.pkg

Procedure Test
    Boolean iSuccess
    Handle hoPubKey
    String sThumbprint
    String sTemp1
    Boolean bTemp1

    Move False To iSuccess

    //  Load a public key to export.  LoadFromFile inspects the content, so it accepts DER, PEM, XML,
    //  JWK, and other supported representations.
    Get Create (RefClass(cComChilkatPublicKey)) To hoPubKey
    If (Not(IsComObjectCreated(hoPubKey))) Begin
        Send CreateComObject of hoPubKey
    End
    Get ComLoadFromFile Of hoPubKey "qa_data/public.pem" To iSuccess
    If (iSuccess = False) Begin
        Get ComLastErrorText Of hoPubKey To sTemp1
        Showln sTemp1
        Procedure_Return
    End

    //  Compute the RFC 7638 JWK thumbprint of the public key using the named hash algorithm.  Common
    //  values include "sha256".
    Get ComGetJwkThumbprint Of hoPubKey "sha256" To sThumbprint
    Get ComLastMethodSuccess Of hoPubKey To bTemp1
    If (bTemp1 = False) Begin
        Get ComLastErrorText Of hoPubKey To sTemp1
        Showln sTemp1
        Procedure_Return
    End

    Showln "JWK thumbprint: " sThumbprint


End_Procedure