Software Components Home

ASP to List Digital Certificates and Private Key Availability

Back

Question:
How can I determine what certificates are available to my ASP application for creating digital signatures?

Answer:
This ASP script will list the certificates in both the Current-User and Local-Machine certificate stores, and will indicate whether or not a private key is available.

<html>
<body>
<%
set ccs = Server.CreateObject("ChilkatCertificate.ChilkatCreateCS")

Response.Write "<b>Current User Certificate Store</b><br>"

set cs = ccs.OpenCurrentUserStore()
numCerts = cs.NumCertificates
if (numCerts = 0) then
	Response.Write "No Certificates!<br>"
end if 

for i = 0 to numCerts-1
	set cert = cs.GetCertificate(i)
	Response.Write cert.SubjectDN
	if (cert.HasPrivateKey() = 1) then
		Response.Write " ++ Has Private Key<br>"
	else
		Response.Write " -- No Private Key<br>"
	end if	
next

Response.Write "<br>"

Response.Write "<b>Local Machine Certificate Store</b><br>"

set cs = ccs.OpenLocalSystemStore()
numCerts = cs.NumCertificates
if (numCerts = 0) then
	Response.Write "No Certificates!<br>"
end if 

for i = 0 to numCerts-1
	set cert = cs.GetCertificate(i)
	Response.Write cert.SubjectDN
	if (cert.HasPrivateKey() = 1) then
		Response.Write " ++ Has Private Key<br>"
	else
		Response.Write " -- No Private Key<br>"
	end if	
next

Response.Write "<br>"

%>
</body>
</html>