Chilkat HOME .NET Core C# Android™ AutoIt C C# C++ Chilkat2-Python CkPython Classic ASP DataFlex Delphi ActiveX Delphi DLL Go Java Lianja Mono C# Node.js Objective-C PHP ActiveX PHP Extension Perl PowerBuilder PowerShell PureBasic Ruby SQL Server Swift 2 Swift 3,4,5... Tcl Unicode C Unicode C++ VB.NET VBScript Visual Basic 6.0 Visual FoxPro Xojo Plugin
(SQL Server) Compute JWK Thumbprint for RSA and EC Private KeysDemonstrates how to compute a JSON Web Key thumbprint for a private key (RSA or ECC). Note: This example requires Chilkat v9.5.0.66 or greater.
-- Important: See this note about string length limitations for strings returned by sp_OAMethod calls. -- CREATE PROCEDURE ChilkatSample AS BEGIN DECLARE @hr int -- Important: Do not use nvarchar(max). See the warning about using nvarchar(max). DECLARE @sTmp0 nvarchar(4000) DECLARE @privKey int -- Use "Chilkat_9_5_0.PrivateKey" for versions of Chilkat < 10.0.0 EXEC @hr = sp_OACreate 'Chilkat.PrivateKey', @privKey OUT IF @hr <> 0 BEGIN PRINT 'Failed to create ActiveX component' RETURN END -- A private key can be loaded from any format (binary DER, PEM, etc.) -- This example will load the private keys from PEM format, -- and will then compute the JWK thumbprint. -- First do it for this RSA private key... DECLARE @sbPem int -- Use "Chilkat_9_5_0.StringBuilder" for versions of Chilkat < 10.0.0 EXEC @hr = sp_OACreate 'Chilkat.StringBuilder', @sbPem OUT DECLARE @bCrlf int SELECT @bCrlf = 1 DECLARE @success int EXEC sp_OAMethod @sbPem, 'AppendLine', @success OUT, '-----BEGIN RSA PRIVATE KEY-----', @bCrlf EXEC sp_OAMethod @sbPem, 'AppendLine', @success OUT, 'Proc-Type: 4,ENCRYPTED', @bCrlf EXEC sp_OAMethod @sbPem, 'AppendLine', @success OUT, 'DEK-Info: DES-EDE3-CBC,2E65118E6C7B5207', @bCrlf EXEC sp_OAMethod @sbPem, 'AppendLine', @success OUT, '', @bCrlf EXEC sp_OAMethod @sbPem, 'AppendLine', @success OUT, '7cYUTW4ZBdmVZ4ILB08hcTdm5ib0E0zcy+I7pHpNQfJHtI7BJ4omys5S19ufJPBJ', @bCrlf EXEC sp_OAMethod @sbPem, 'AppendLine', @success OUT, 'IzYjeO7oTVqI37F6EUmjZqG4WVE2UQbQDkosZbZN82O4Ipu1lFAPEbwjqePMKufz', @bCrlf EXEC sp_OAMethod @sbPem, 'AppendLine', @success OUT, 'snSQHKfnbyyDPEVNlJbs19NXC8v6g+pQay5rH/I6N2iBxgsTmuemZ54EhNQMZyEN', @bCrlf EXEC sp_OAMethod @sbPem, 'AppendLine', @success OUT, 'R/CiheArWEH9H8/4hd2gc9Tb2s0MwGHILL4kbbNm5tp3xw4ik7OYWNrj3m+nG6Xb', @bCrlf EXEC sp_OAMethod @sbPem, 'AppendLine', @success OUT, 'vKXh2xEanAZAyMXTqDJTHdn7/CEqusQPJjZGV+Mf1kjKu7p4qcXFnIXP5ILnTW7b', @bCrlf EXEC sp_OAMethod @sbPem, 'AppendLine', @success OUT, 'lHoWC4eweDzKOMRzXmbABEVSUvx2SmPl4TcoC5L1SCAHEmZaKbaY7S5l53u6gl0f', @bCrlf EXEC sp_OAMethod @sbPem, 'AppendLine', @success OUT, 'ULuQbt7Hr3THznlNFKkGT1/yVNt2QOm1emZd55LaNe8E7XsNSlhl0grYQ+Ue8Jba', @bCrlf EXEC sp_OAMethod @sbPem, 'AppendLine', @success OUT, 'x85OapltVjxM9wVCwbgFyi04ihdKHo9e+uYKeTGKv0hU5O7HEH1ev6t/s2u/UG6h', @bCrlf EXEC sp_OAMethod @sbPem, 'AppendLine', @success OUT, 'TqEsYrVp0CMHpt5uAF6nZyK6GZ/CHTxh/rz1hADMofem59+e6tVtjnPGA3EjnJT8', @bCrlf EXEC sp_OAMethod @sbPem, 'AppendLine', @success OUT, 'BMOw/D2QIDxjxj2GUzz+YJp50ENhWrL9oSDkG2nzv4NVL77QIy+T/2/f4PgokUDO', @bCrlf EXEC sp_OAMethod @sbPem, 'AppendLine', @success OUT, 'QJjIfxPWE40cHGHpnQtZvEPoxP0H3T0YhmEVwuJxX3uaWOY/8Fa1c7Ln0SwWdfV5', @bCrlf EXEC sp_OAMethod @sbPem, 'AppendLine', @success OUT, 'gYvJV8o6c3sumcq1O3agPDlHC5O4IxG7AZQ8CHRDyASogzfkY6P579ZOGYaO4al7', @bCrlf EXEC sp_OAMethod @sbPem, 'AppendLine', @success OUT, 'WA1YIpsHs3/1f4SByMuWe0NVkFfvXckjpqGrBQpTmqQzk6baa0VQ0cwU3XlkwHac', @bCrlf EXEC sp_OAMethod @sbPem, 'AppendLine', @success OUT, 'WB/fQ4jylwFzZDcp5JAo53n6aU72zgNvDlGTNKwdXXZI5U3JPocH0AiZgFFWYJLd', @bCrlf EXEC sp_OAMethod @sbPem, 'AppendLine', @success OUT, '63PJLDnjyE3i6XMVlxifXKkXVv0RYSz+ByS7Oz9aCgnQhNU8ycv+UxtfkPQih5zE', @bCrlf EXEC sp_OAMethod @sbPem, 'AppendLine', @success OUT, '/0Y2EEFknajmFJpNXczzF8OEzaswmR0AOjcCiklZKRf61rf5faJxJhhqKEEBJuL6', @bCrlf EXEC sp_OAMethod @sbPem, 'AppendLine', @success OUT, 'oodDVRk3OGU1yQSBazT8nK3V+e6FMo3tWkra2BXFCD+pKxTy014Cp59S1w6F1Fjt', @bCrlf EXEC sp_OAMethod @sbPem, 'AppendLine', @success OUT, 'WX7eMWSLWfQ56j2kLMBHq5gb2arqlqH3fsYOTD3TNjCYF3Sgx309kVPuOK5vw61P', @bCrlf EXEC sp_OAMethod @sbPem, 'AppendLine', @success OUT, 'pnL/LN3iGY42WR+9lfAyNN2qj9zvwKwscyYs5+DPQoPmcPcVGc3v/u66bLcOGbEU', @bCrlf EXEC sp_OAMethod @sbPem, 'AppendLine', @success OUT, 'OlGa/6gdD4GCp5E4fP/7GbnEY/PW2abquFhGB+pVdl3/4+1U/8kItlfWNZoG4FhE', @bCrlf EXEC sp_OAMethod @sbPem, 'AppendLine', @success OUT, 'gjMd7glmrdFiNJFFpf5ks1lVXGqJ4mZxqtEZrxUEwciZjm4V27a+E2KyV9NnksZ6', @bCrlf EXEC sp_OAMethod @sbPem, 'AppendLine', @success OUT, 'xF4tGPKIPsvNTV5o8ZqjiacxgbYmr2ywqDXKCgpU/RWSh1sLapqSQqbH/w0MquUj', @bCrlf EXEC sp_OAMethod @sbPem, 'AppendLine', @success OUT, 'VhVX0RMYH/foKtjagZf/KO1/mnCITl86treIdachGgR4wr/qqMjrpPUaPLCRY3JQ', @bCrlf EXEC sp_OAMethod @sbPem, 'AppendLine', @success OUT, '00XUP1Mu6YPE0SnMYAVxZheqKHly3a1pg4Xp7YWlM671oUORs3+VENfnbIxgr+2D', @bCrlf EXEC sp_OAMethod @sbPem, 'AppendLine', @success OUT, 'TiJT9PxwpfK53Oh7RBSWHJZRuAdLUXE8DG+bl0N/QkJM6pFUxTI1AQ==', @bCrlf EXEC sp_OAMethod @sbPem, 'AppendLine', @success OUT, '-----END RSA PRIVATE KEY-----', @bCrlf -- The actual password for the above PEM is "passwd". DECLARE @success int EXEC sp_OAMethod @sbPem, 'GetAsString', @sTmp0 OUT EXEC sp_OAMethod @privKey, 'LoadEncryptedPem', @success OUT, @sTmp0, 'passwd' IF @success <> 1 BEGIN EXEC sp_OAGetProperty @privKey, 'LastErrorText', @sTmp0 OUT PRINT @sTmp0 EXEC @hr = sp_OADestroy @privKey EXEC @hr = sp_OADestroy @sbPem RETURN END -- Generate the JWK thumbprint: EXEC sp_OAMethod @privKey, 'GetJwkThumbprint', @sTmp0 OUT, 'SHA256' PRINT 'JWK thumbprint: ' + @sTmp0 -- Output: -- JWK thumbprint: QzUpUAW1Y5iksGxq3r1o3JMROR6D7FLwvRlHmDQVg0I -- -------------------------------------------------------------- -- Now let's do an EC private key. The following is an unencrypted PEM containing a 384-bit EC key.. EXEC sp_OAMethod @sbPem, 'Clear', NULL EXEC sp_OAMethod @sbPem, 'AppendLine', @success OUT, '-----BEGIN PRIVATE KEY-----', @bCrlf EXEC sp_OAMethod @sbPem, 'AppendLine', @success OUT, 'MIG2AgEAMBAGByqGSM49AgEGBSuBBAAiBIGeMIGbAgEBBDAamStb0Xep3y3sWw2u', @bCrlf EXEC sp_OAMethod @sbPem, 'AppendLine', @success OUT, 'SSAdUPkgQ9Rvhlnx8XEVOYy2teh69T0on77ja02m03n8t8WhZANiAARUNSar38Rz', @bCrlf EXEC sp_OAMethod @sbPem, 'AppendLine', @success OUT, 'lKPyZFsNSGUanzpNRth0C+MikVEH8FAlDHMMpAs34dyF4IK0uxgbiEe9bQ+ieLrl', @bCrlf EXEC sp_OAMethod @sbPem, 'AppendLine', @success OUT, '6xwFR0yaTivuwoyXC+ScGUnwnpaXmid6UUgw4ypbneHsaKuZ9JLdMAo=', @bCrlf EXEC sp_OAMethod @sbPem, 'AppendLine', @success OUT, '-----END PRIVATE KEY-----', @bCrlf EXEC sp_OAMethod @sbPem, 'GetAsString', @sTmp0 OUT EXEC sp_OAMethod @privKey, 'LoadPem', @success OUT, @sTmp0 IF @success <> 1 BEGIN EXEC sp_OAGetProperty @privKey, 'LastErrorText', @sTmp0 OUT PRINT @sTmp0 EXEC @hr = sp_OADestroy @privKey EXEC @hr = sp_OADestroy @sbPem RETURN END -- Generate the JWK thumbprint: EXEC sp_OAMethod @privKey, 'GetJwkThumbprint', @sTmp0 OUT, 'SHA256' PRINT 'JWK thumbprint: ' + @sTmp0 -- Output: -- JWK thumbprint: ABAUUfNSONFsZYvZ_o_0bsPT3qeG3jttXB09VC_ETWQ EXEC @hr = sp_OADestroy @privKey EXEC @hr = sp_OADestroy @sbPem END GO |
© 2000-2024 Chilkat Software, Inc. All Rights Reserved.