SQL Server
SQL Server
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 SQL Server Downloads
-- 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 public key to export. LoadFromFile inspects the content, so it accepts DER, PEM, XML,
-- JWK, and other supported representations.
DECLARE @pubKey int
EXEC @hr = sp_OACreate 'Chilkat.PublicKey', @pubKey OUT
IF @hr <> 0
BEGIN
PRINT 'Failed to create ActiveX component'
RETURN
END
EXEC sp_OAMethod @pubKey, 'LoadFromFile', @success OUT, 'qa_data/public.pem'
IF @success = 0
BEGIN
EXEC sp_OAGetProperty @pubKey, 'LastErrorText', @sTmp0 OUT
PRINT @sTmp0
EXEC @hr = sp_OADestroy @pubKey
RETURN
END
-- Compute the RFC 7638 JWK thumbprint of the public key using the named hash algorithm. Common
-- values include "sha256".
DECLARE @thumbprint nvarchar(4000)
EXEC sp_OAMethod @pubKey, 'GetJwkThumbprint', @thumbprint OUT, 'sha256'
EXEC sp_OAGetProperty @pubKey, 'LastMethodSuccess', @iTmp0 OUT
IF @iTmp0 = 0
BEGIN
EXEC sp_OAGetProperty @pubKey, 'LastErrorText', @sTmp0 OUT
PRINT @sTmp0
EXEC @hr = sp_OADestroy @pubKey
RETURN
END
PRINT 'JWK thumbprint: ' + @thumbprint
EXEC @hr = sp_OADestroy @pubKey
END
GO