Chilkat Examples

ChilkatHOME.NET Core C#Android™AutoItCC#C++Chilkat2-PythonCkPythonClassic ASPDataFlexDelphi ActiveXDelphi DLLGoJavaLianjaMono C#Node.jsObjective-CPHP ActiveXPHP ExtensionPerlPowerBuilderPowerShellPureBasicRubySQL ServerSwift 2Swift 3,4,5...TclUnicode CUnicode C++VB.NETVBScriptVisual Basic 6.0Visual FoxProXojo Plugin

Classic ASP Examples

Web API Categories

ASN.1
AWS KMS
AWS Misc
Amazon EC2
Amazon Glacier
Amazon S3
Amazon S3 (new)
Amazon SES
Amazon SNS
Amazon SQS
Async
Azure Cloud Storage
Azure Key Vault
Azure Service Bus
Azure Table Service
Base64
Bounced Email
Box
CAdES
CSR
CSV
Certificates
Code Signing
Compression
DKIM / DomainKey
DNS
DSA
Diffie-Hellman
Digital Signatures
Dropbox
Dynamics CRM
EBICS
ECC
Ed25519
Email Object
Encryption
FTP
FileAccess
Firebase
GMail REST API
GMail SMTP/IMAP/POP
Geolocation
Google APIs
Google Calendar
Google Cloud SQL
Google Cloud Storage
Google Drive
Google Photos
Google Sheets
Google Tasks
Gzip
HTML-to-XML/Text
HTTP

HTTP Misc
IMAP
JSON
JSON Web Encryption (JWE)
JSON Web Signatures (JWS)
JSON Web Token (JWT)
Java KeyStore (JKS)
MHT / HTML Email
MIME
MS Storage Providers
Microsoft Graph
Misc
NTLM
OAuth1
OAuth2
OIDC
Office365
OneDrive
OpenSSL
Outlook
Outlook Calendar
Outlook Contact
PDF Signatures
PEM
PFX/P12
PKCS11
POP3
PRNG
REST
REST Misc
RSA
SCP
SCard
SFTP
SMTP
SSH
SSH Key
SSH Tunnel
ScMinidriver
SharePoint
SharePoint Online
Signing in the Cloud
Socket/SSL/TLS
Spider
Stream
Tar Archive
ULID/UUID
Upload
WebSocket
XAdES
XML
XML Digital Signatures
XMP
Zip
curl
uncategorized

 

 

 

Extract Public/Private Keys and Certs from PFX into String Variables

Demonstrates how to export certificates and public/private keys from a PFX file into in-memory strings.

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<body>
<%

set certStore = Server.CreateObject("Chilkat_9_5_0.CertStore")

'  Load the PFX file into a certificate store object

password = "*myPassword2*"
success = certStore.LoadPfxFile("chilkat.pfx",password)
If (success <> 1) Then
    Response.Write certStore.LastErrorText & "<br>"

End If

numCerts = certStore.NumCertificates

'  Loop over each certificate in the PFX.

For i = 0 To numCerts - 1

    Set cert = certStore.GetCertificate(i)

    Response.Write cert.SubjectDN & "<br>"
    Response.Write "---" & "<br>"

    encodedCert = cert.GetEncoded()

    '  This string may now be stored in a relational database string field.
    '  To re-create the cert, do this:
    set cert2 = Server.CreateObject("Chilkat_9_5_0.Cert")
    cert2.SetFromEncoded encodedCert

    '  Does this cert have a private key?
    If (cert.HasPrivateKey() = 1) Then

        '  Get the private key.

        Set pvkey = cert.ExportPrivateKey()

        '  The private key can be exported into
        '  a string in PKCS8, RSA PEM, or XML format:

        pemPvKey = pvkey.GetRsaPem()
        pkcs8PvKey = pvkey.GetPkcs8Pem()
        xmlPvKey = pvkey.GetXml()

        Response.Write pemPvKey & "<br>"
        Response.Write pkcs8PvKey & "<br>"
        Response.Write xmlPvKey & "<br>"

        '  Any of these formatted strings may
        '  be stored in a relational database field.
        '  to restore, call LoadPem or LoadXml
        '  LoadPem accepts either RSA PEM or
        '  PKCS8 PEM:
        set pvKey2 = Server.CreateObject("Chilkat_9_5_0.PrivateKey")

        pvKey2.LoadPem pemPvKey
        pvKey2.LoadPem pkcs8PvKey
        pvKey2.LoadXml xmlPvKey

    End If

    '  Now for the public key:

    Set pubkey = cert.ExportPublicKey()

    '  It can be exported to a string as OpenSSL PEM
    '  or XML:

    pubKeyPem = pubkey.GetOpenSslPem()
    pubKeyXml = pubkey.GetXml()

    Response.Write pubKeyPem & "<br>"
    Response.Write pubKeyXml & "<br>"

    '  To re-load a PublicKey object, call LoadXml
    '  or LoadOpenSslPem:
    set pubKey2 = Server.CreateObject("Chilkat_9_5_0.PublicKey")

    pubKey2.LoadOpenSslPem pubKeyPem
    pubKey2.LoadXml pubKeyXml
    fname = "pubkey" & CStr(i) & "_openSsl.der"
    pubkey.SaveOpenSslDerFile fname

Next

'  The Chilkat Certificate, Certificate Store, Private Key,
'  Public Key, and Key Container classes / objects are freeware.

'  They are used by and included with the Chilkat Email,
'  Crypt, S/MIME, and other commercial Chilkat components.

%>
</body>
</html>

 

© 2000-2024 Chilkat Software, Inc. All Rights Reserved.