Sample code for 30+ languages & platforms
SQL Server

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 SQL Server Downloads

SQL Server
-- Important: See this note about string length limitations for strings returned by sp_OAMethod calls.
--
CREATE PROCEDURE ChilkatSample
AS
BEGIN
    DECLARE @hr int
    DECLARE @iTmp0 int
    DECLARE @sTmp0 nvarchar(4000)
    DECLARE @success int
    SELECT @success = 0

    --  Load a private key to export.
    DECLARE @privKey int
    EXEC @hr = sp_OACreate 'Chilkat.PrivateKey', @privKey OUT
    IF @hr <> 0
    BEGIN
        PRINT 'Failed to create ActiveX component'
        RETURN
    END

    EXEC sp_OAMethod @privKey, 'LoadPemFile', @success OUT, 'qa_data/private.pem'
    IF @success = 0
      BEGIN
        EXEC sp_OAGetProperty @privKey, 'LastErrorText', @sTmp0 OUT
        PRINT @sTmp0
        EXEC @hr = sp_OADestroy @privKey
        RETURN
      END

    --  Compute the RFC 7638 thumbprint of the key's public portion using the named hash algorithm.
    --  Supported values include "sha256", "sha1", "md5", and others.
    DECLARE @thumbprint nvarchar(4000)
    EXEC sp_OAMethod @privKey, 'GetJwkThumbprint', @thumbprint OUT, 'sha256'
    EXEC sp_OAGetProperty @privKey, 'LastMethodSuccess', @iTmp0 OUT
    IF @iTmp0 = 0
      BEGIN
        EXEC sp_OAGetProperty @privKey, 'LastErrorText', @sTmp0 OUT
        PRINT @sTmp0
        EXEC @hr = sp_OADestroy @privKey
        RETURN
      END

    PRINT 'JWK thumbprint: ' + @thumbprint

    EXEC @hr = sp_OADestroy @privKey


END
GO