Classic ASP
Classic ASP
Add a Private Key and Certificate Chain to a PFX
See more PFX/P12 Examples
Demonstrates Pfx.AddPrivateKey, which adds a private key together with its certificate chain to the PFX object.
The file path is relative to the application's current working directory. An absolute path may also be used. Supply the path appropriate to your own environment.
Background. The chain must contain at least one certificate; the certificate at index 0 is treated as the leaf. The chain is built here with Cert.BuildCertChain.
Chilkat Classic ASP Downloads
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<body>
<%
success = 0
set pfx = Server.CreateObject("Chilkat.Pfx")
' The file path is relative to the application's current working directory. An absolute path
' may also be used. Supply the path appropriate to your own environment.
' Load the private key.
set privKey = Server.CreateObject("Chilkat.PrivateKey")
success = privKey.LoadPemFile("qa_data/private_key.pem")
If (success = 0) Then
Response.Write "<pre>" & Server.HTMLEncode( privKey.LastErrorText) & "</pre>"
Response.End
End If
' Load the certificate and build its chain of authority. The chain must contain at least one
' certificate; the certificate at index 0 is treated as the leaf.
set cert = Server.CreateObject("Chilkat.Cert")
success = cert.LoadFromFile("qa_data/cert.pem")
If (success = 0) Then
Response.Write "<pre>" & Server.HTMLEncode( cert.LastErrorText) & "</pre>"
Response.End
End If
set chain = Server.CreateObject("Chilkat.CertChain")
success = cert.BuildCertChain(chain)
If (success = 0) Then
Response.Write "<pre>" & Server.HTMLEncode( cert.LastErrorText) & "</pre>"
Response.End
End If
' Add the private key and its certificate chain to the PFX.
success = pfx.AddPrivateKey(privKey,chain)
If (success = 0) Then
Response.Write "<pre>" & Server.HTMLEncode( pfx.LastErrorText) & "</pre>"
Response.End
End If
Response.Write "<pre>" & Server.HTMLEncode( "Private key and certificate chain added to the PFX.") & "</pre>"
%>
</body>
</html>