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) Load Encrypted PEM Containing ECC Private Key and Certs and Examine ContentsLoads an encrypted PEM containing an ECC private key and ECC certificate (and chain), and examines the contents. Note: This example requires Chilkat v9.5.0.66.
-- 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 -- Important: Do not use nvarchar(max). See the warning about using nvarchar(max). DECLARE @sTmp0 nvarchar(4000) -- Note: This example requires Chilkat v9.5.0.66. -- This example requires the Chilkat API to have been previously unlocked. -- See Global Unlock Sample for sample code. -- Create a PEM containing a valid EC private key and certificates. -- The password for this encrypted PEM is "secret123" DECLARE @sb int -- Use "Chilkat_9_5_0.StringBuilder" for versions of Chilkat < 10.0.0 EXEC @hr = sp_OACreate 'Chilkat.StringBuilder', @sb OUT IF @hr <> 0 BEGIN PRINT 'Failed to create ActiveX component' RETURN END DECLARE @bCrlf int SELECT @bCrlf = 1 DECLARE @success int EXEC sp_OAMethod @sb, 'AppendLine', @success OUT, '-----BEGIN ENCRYPTED PRIVATE KEY-----', @bCrlf EXEC sp_OAMethod @sb, 'AppendLine', @success OUT, 'MIGtMEkGCSqGSIb3DQEFDTA8MBsGCSqGSIb3DQEFDDAOBAiweNs9xIWNoAICCAAw', @bCrlf EXEC sp_OAMethod @sb, 'AppendLine', @success OUT, 'HQYJYIZIAWUDBAECBBCz0IMryNxuJEo5ChMktg9cBGCsKDEeRqGJX4g/X2c6CNtK', @bCrlf EXEC sp_OAMethod @sb, 'AppendLine', @success OUT, 'I8q7KClUwy9ms7ckHZAw/997WuW9QIGGnJEfHL/jSJsZViDwFAB4sunmdHSOTGMD', @bCrlf EXEC sp_OAMethod @sb, 'AppendLine', @success OUT, '3ZINNlkA+XobMaQtj1HNERtb1qskW1mf/X0sauw5aPA=', @bCrlf EXEC sp_OAMethod @sb, 'AppendLine', @success OUT, '-----END ENCRYPTED PRIVATE KEY-----', @bCrlf EXEC sp_OAMethod @sb, 'AppendLine', @success OUT, '-----BEGIN CERTIFICATE-----', @bCrlf EXEC sp_OAMethod @sb, 'AppendLine', @success OUT, 'MIICzjCCAlOgAwIBAgIETULS8zAKBggqhkjOPQQDAzBtMQswCQYDVQQGEwJVUzEW', @bCrlf EXEC sp_OAMethod @sb, 'AppendLine', @success OUT, 'MBQGA1UEChMNRW50cnVzdCwgSW5jLjEfMB0GA1UECxMWRm9yIFRlc3QgUHVycG9z', @bCrlf EXEC sp_OAMethod @sb, 'AppendLine', @success OUT, 'ZXMgT25seTElMCMGA1UEAxMcRW50cnVzdCBFQ0MgRGVtb25zdHJhdGlvbiBDQTAe', @bCrlf EXEC sp_OAMethod @sb, 'AppendLine', @success OUT, 'Fw0xNjAzMTgxMjM5MzFaFw0xNjA1MTcxMzA5MzFaMFgxHzAdBgNVBAsTFkZvciBU', @bCrlf EXEC sp_OAMethod @sb, 'AppendLine', @success OUT, 'ZXN0IFB1cnBvc2VzIE9ubHkxHTAbBgNVBAsTFFBlcnNvbmEgTm90IFZlcmlmaWVk', @bCrlf EXEC sp_OAMethod @sb, 'AppendLine', @success OUT, 'MRYwFAYDVQQDEw1DaGlsa2F0IEFkbWluMHYwEAYHKoZIzj0CAQYFK4EEACIDYgAE', @bCrlf EXEC sp_OAMethod @sb, 'AppendLine', @success OUT, 'uB62JGMJKXnp1PNsOOIYKGhrzfLev3O+UuthL6UzEqNNDTd8dEYMUQP/DTS3qk98', @bCrlf EXEC sp_OAMethod @sb, 'AppendLine', @success OUT, 'gyQEFxdmZUsPF0fFokkZZ1cV6z7QD3MsPvSjrBzB0GUB3r8CLnDK/F4pF2Q995hr', @bCrlf EXEC sp_OAMethod @sb, 'AppendLine', @success OUT, 'o4HYMIHVMA4GA1UdDwEB/wQEAwIDiDAdBgNVHSUEFjAUBggrBgEFBQcDAgYIKwYB', @bCrlf EXEC sp_OAMethod @sb, 'AppendLine', @success OUT, 'BQUHAwQwNwYDVR0fBDAwLjAsoCqgKIYmaHR0cDovL2NybC5lbnRydXN0LmNvbS9D', @bCrlf EXEC sp_OAMethod @sb, 'AppendLine', @success OUT, 'UkwvZWNjZGVtby5jcmwwIAYDVR0RBBkwF4EVYWRtaW5AY2hpbGthdHNvZnQuY29t', @bCrlf EXEC sp_OAMethod @sb, 'AppendLine', @success OUT, 'MB8GA1UdIwQYMBaAFCQFS+Fkghr4Ccz7eHkh+nDmkzLqMB0GA1UdDgQWBBTB82fm', @bCrlf EXEC sp_OAMethod @sb, 'AppendLine', @success OUT, 'vrdG2iX5uS/agVW3L4DisjAJBgNVHRMEAjAAMAoGCCqGSM49BAMDA2kAMGYCMQCH', @bCrlf EXEC sp_OAMethod @sb, 'AppendLine', @success OUT, 'ILghMprWoYPEp9mCE+tpVE7vYwkFV3m0RDzT2BSUezL8Ky78XNk+XPqSB2biT70C', @bCrlf EXEC sp_OAMethod @sb, 'AppendLine', @success OUT, 'MQDCase1oaPY4AxCmjB+rEB1ir+QS8mrtF+iCSqHVv1aIxT6abQL57BZSdvwIm/T', @bCrlf EXEC sp_OAMethod @sb, 'AppendLine', @success OUT, 'T8o=', @bCrlf EXEC sp_OAMethod @sb, 'AppendLine', @success OUT, '-----END CERTIFICATE-----', @bCrlf EXEC sp_OAMethod @sb, 'AppendLine', @success OUT, '-----BEGIN CERTIFICATE-----', @bCrlf EXEC sp_OAMethod @sb, 'AppendLine', @success OUT, 'MIICljCCAhugAwIBAgIETUHhezAKBggqhkjOPQQDAzBtMQswCQYDVQQGEwJVUzEW', @bCrlf EXEC sp_OAMethod @sb, 'AppendLine', @success OUT, 'MBQGA1UEChMNRW50cnVzdCwgSW5jLjEfMB0GA1UECxMWRm9yIFRlc3QgUHVycG9z', @bCrlf EXEC sp_OAMethod @sb, 'AppendLine', @success OUT, 'ZXMgT25seTElMCMGA1UEAxMcRW50cnVzdCBFQ0MgRGVtb25zdHJhdGlvbiBDQTAe', @bCrlf EXEC sp_OAMethod @sb, 'AppendLine', @success OUT, 'Fw0xMTAxMjcyMDQ5NTRaFw0zNjAxMjcyMTE5NTRaMG0xCzAJBgNVBAYTAlVTMRYw', @bCrlf EXEC sp_OAMethod @sb, 'AppendLine', @success OUT, 'FAYDVQQKEw1FbnRydXN0LCBJbmMuMR8wHQYDVQQLExZGb3IgVGVzdCBQdXJwb3Nl', @bCrlf EXEC sp_OAMethod @sb, 'AppendLine', @success OUT, 'cyBPbmx5MSUwIwYDVQQDExxFbnRydXN0IEVDQyBEZW1vbnN0cmF0aW9uIENBMHYw', @bCrlf EXEC sp_OAMethod @sb, 'AppendLine', @success OUT, 'EAYHKoZIzj0CAQYFK4EEACIDYgAEhCWBpuJuzvRtQyibkcbCj7EkcwAqS2EqRQ/Q', @bCrlf EXEC sp_OAMethod @sb, 'AppendLine', @success OUT, 'ntroTdRM2SssEN4TruTxtwcY/7lR64L6Tfjz3+ujrfjNFss3EWVpUlbOJ+xHC3xH', @bCrlf EXEC sp_OAMethod @sb, 'AppendLine', @success OUT, 'PteNyAGZtHbZO3tVuhP6yX6dFqCCo4GLMIGIMCsGA1UdEAQkMCKADzIwMTEwMTI3', @bCrlf EXEC sp_OAMethod @sb, 'AppendLine', @success OUT, 'MjA0OTU0WoEPMjAzNjAxMjcyMTE5NTRaMAsGA1UdDwQEAwIBBjAfBgNVHSMEGDAW', @bCrlf EXEC sp_OAMethod @sb, 'AppendLine', @success OUT, 'gBQkBUvhZIIa+AnM+3h5Ifpw5pMy6jAdBgNVHQ4EFgQUJAVL4WSCGvgJzPt4eSH6', @bCrlf EXEC sp_OAMethod @sb, 'AppendLine', @success OUT, 'cOaTMuowDAYDVR0TBAUwAwEB/zAKBggqhkjOPQQDAwNpADBmAjEAyAhA70OIb6lb', @bCrlf EXEC sp_OAMethod @sb, 'AppendLine', @success OUT, 'fN6kOTQloHyCLmihNK+PT5wOuaMR//KSQP2c/H18YhDYnlwMxF9fAjEA0URaJOXM', @bCrlf EXEC sp_OAMethod @sb, 'AppendLine', @success OUT, 'F0qwdvS2rm7N5PWMLc/4BbeOZyZ94XJiG5u96iTgp6N9JI0MMmCQE87N', @bCrlf EXEC sp_OAMethod @sb, 'AppendLine', @success OUT, '-----END CERTIFICATE-----', @bCrlf DECLARE @pem int -- Use "Chilkat_9_5_0.Pem" for versions of Chilkat < 10.0.0 EXEC @hr = sp_OACreate 'Chilkat.Pem', @pem OUT DECLARE @success int EXEC sp_OAMethod @sb, 'GetAsString', @sTmp0 OUT EXEC sp_OAMethod @pem, 'LoadPem', @success OUT, @sTmp0, 'secret123' IF @success <> 1 BEGIN EXEC sp_OAGetProperty @pem, 'LastErrorText', @sTmp0 OUT PRINT @sTmp0 EXEC @hr = sp_OADestroy @sb EXEC @hr = sp_OADestroy @pem RETURN END -- Get the private key and examine it in JSON Web Key form (JWK) DECLARE @privKey int EXEC sp_OAMethod @pem, 'GetPrivateKey', @privKey OUT, 0 EXEC sp_OAGetProperty @pem, 'LastMethodSuccess', @iTmp0 OUT IF @iTmp0 <> 1 BEGIN EXEC sp_OAGetProperty @pem, 'LastErrorText', @sTmp0 OUT PRINT @sTmp0 EXEC @hr = sp_OADestroy @sb EXEC @hr = sp_OADestroy @pem RETURN END DECLARE @json int -- Use "Chilkat_9_5_0.JsonObject" for versions of Chilkat < 10.0.0 EXEC @hr = sp_OACreate 'Chilkat.JsonObject', @json OUT EXEC sp_OAMethod @privKey, 'GetJwk', @sTmp0 OUT EXEC sp_OAMethod @json, 'Load', @success OUT, @sTmp0 EXEC sp_OASetProperty @json, 'EmitCompact', 0 EXEC sp_OAMethod @json, 'Emit', @sTmp0 OUT PRINT @sTmp0 EXEC @hr = sp_OADestroy @privKey -- JWK output: -- { -- "kty": "EC", -- "crv": "P-384", -- "x": "uB62JGMJKXnp1PNsOOIYKGhrzfLev3O-UuthL6UzEqNNDTd8dEYMUQP_DTS3qk98", -- "y": "gyQEFxdmZUsPF0fFokkZZ1cV6z7QD3MsPvSjrBzB0GUB3r8CLnDK_F4pF2Q995hr", -- "d": "ugTy2ZpuQqv1uQyLSgz1SPRvngzrd5vLyzU2ICaJd25zZRIxxlNR-uFo9UWC6llt" -- } -- Now get 1st certificate and examine in XML format: DECLARE @cert int EXEC sp_OAMethod @pem, 'GetCert', @cert OUT, 0 EXEC sp_OAGetProperty @pem, 'LastMethodSuccess', @iTmp0 OUT IF @iTmp0 <> 1 BEGIN EXEC sp_OAGetProperty @pem, 'LastErrorText', @sTmp0 OUT PRINT @sTmp0 EXEC @hr = sp_OADestroy @sb EXEC @hr = sp_OADestroy @pem EXEC @hr = sp_OADestroy @json RETURN END DECLARE @certXml nvarchar(4000) EXEC sp_OAMethod @cert, 'ExportCertXml', @certXml OUT EXEC @hr = sp_OADestroy @cert PRINT @certXml -- XML output: -- <?xml version="1.0" encoding="utf-8" ?> -- <sequence> -- <sequence> -- <contextSpecific tag="0" constructed="1"> -- <int>02</int> -- </contextSpecific> -- <int>4D42D2F3</int> -- <sequence> -- <oid>1.2.840.10045.4.3.3</oid> -- </sequence> -- <sequence> -- <set> -- <sequence> -- <oid>2.5.4.6</oid> -- <printable>US</printable> -- </sequence> -- </set> -- <set> -- <sequence> -- <oid>2.5.4.10</oid> -- <printable>Entrust, Inc.</printable> -- </sequence> -- </set> -- <set> -- <sequence> -- <oid>2.5.4.11</oid> -- <printable>For Test Purposes Only</printable> -- </sequence> -- </set> -- <set> -- <sequence> -- <oid>2.5.4.3</oid> -- <printable>Entrust ECC Demonstration CA</printable> -- </sequence> -- </set> -- </sequence> -- <sequence> -- <utctime>160318123931Z</utctime> -- <utctime>160517130931Z</utctime> -- </sequence> -- <sequence> -- <set> -- <sequence> -- <oid>2.5.4.11</oid> -- <printable>For Test Purposes Only</printable> -- </sequence> -- </set> -- <set> -- <sequence> -- <oid>2.5.4.11</oid> -- <printable>Persona Not Verified</printable> -- </sequence> -- </set> -- <set> -- <sequence> -- <oid>2.5.4.3</oid> -- <printable>Chilkat Admin</printable> -- </sequence> -- </set> -- </sequence> -- <sequence> -- <sequence> -- <oid>1.2.840.10045.2.1</oid> -- <oid>1.3.132.0.34</oid> -- </sequence> -- <bits n="776">04B81EB62463092979E9D4F36C38E21828686BCDF2DEBF73BE52EB612FA53312A34D0D377C74460C5103FF0D34B7AA4F7C832404171766654B0F1747C5A24919675715EB3ED00F732C3EF4A3AC1CC1D06501DEBF022E70CAFC5E2917643DF7986B</bits> -- </sequence> -- <contextSpecific tag="3" constructed="1"> -- <sequence> -- <sequence> -- <oid>2.5.29.15</oid> -- <bool>1</bool> -- <octets>AwIDiA==</octets> -- </sequence> -- <sequence> -- <oid>2.5.29.37</oid> -- <octets>MBQGCCsGAQUFBwMCBggrBgEFBQcDBA==</octets> -- </sequence> -- <sequence> -- <oid>2.5.29.31</oid> -- <octets>MC4wLKAqoCiGJmh0dHA6Ly9jcmwuZW50cnVzdC5jb20vQ1JML2VjY2RlbW8uY3Js</octets> -- </sequence> -- <sequence> -- <oid>2.5.29.17</oid> -- <octets>MBeBFWFkbWluQGNoaWxrYXRzb2Z0LmNvbQ==</octets> -- </sequence> -- <sequence> -- <oid>2.5.29.35</oid> -- <octets>MBaAFCQFS+Fkghr4Ccz7eHkh+nDmkzLq</octets> -- </sequence> -- <sequence> -- <oid>2.5.29.14</oid> -- <octets>BBTB82fmvrdG2iX5uS/agVW3L4Disg==</octets> -- </sequence> -- <sequence> -- <oid>2.5.29.19</oid> -- <octets>MAA=</octets> -- </sequence> -- </sequence> -- </contextSpecific> -- </sequence> -- <sequence> -- <oid>1.2.840.10045.4.3.3</oid> -- </sequence> -- <bits n="832">30660231008720B821329AD6A183C4A7D98213EB69544EEF6309055779B4443CD3D814947B32FC2B2EFC5CD93E5CFA920766E24FBD023100C26AC7B5A1A3D8E00C429A307EAC40758ABF904BC9ABB45FA2092A8756FD5A2314FA69B40BE7B05949DBF0226FD34FCA</bits> -- </sequence> -- -- -- EXEC @hr = sp_OADestroy @sb EXEC @hr = sp_OADestroy @pem EXEC @hr = sp_OADestroy @json END GO |
© 2000-2024 Chilkat Software, Inc. All Rights Reserved.