Sample code for 30+ languages & platforms
Classic ASP

Get RSA Key Modulus from .cer or .key

See more Certificates Examples

Demonstrates how to get the RSA key modulus from either the certificate (.cer) or RSA key (.key). OpenSSL commands to do the same would be:
openssl x509 -inform DER -in "test.cer"  -modulus -noout 
or
openssl pkcs8 -inform DER -in​ "test.key"​ -outform PEM -passin pass:"12345​678a​"
   | openssl rsa -inform PEM -modulus -noout 

Chilkat Classic ASP Downloads

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

set privKey = Server.CreateObject("Chilkat.PrivateKey")

password = "12345678a"
success = privKey.LoadPkcs8EncryptedFile("qa_data/certs/test_12345678a.key",password)
If (success = 0) Then
    Response.Write "<pre>" & Server.HTMLEncode( privKey.LastErrorText) & "</pre>"
    Response.End
End If

set xml = Server.CreateObject("Chilkat.Xml")
success = xml.LoadXml(privKey.GetXml())

' The XML contains the parts of the key in base64.
Response.Write "<pre>" & Server.HTMLEncode( "Private Key XML:") & "</pre>"
Response.Write "<pre>" & Server.HTMLEncode( xml.GetXml()) & "</pre>"

' We can get the base64 modulus like this:
modulus = xml.GetChildContent("Modulus")
Response.Write "<pre>" & Server.HTMLEncode( "base64 modulus = " & modulus) & "</pre>"

' To convert to hex:
set binDat = Server.CreateObject("Chilkat.BinData")
success = binDat.AppendEncoded(modulus,"base64")
hexModulus = binDat.GetEncoded("hex")
Response.Write "<pre>" & Server.HTMLEncode( "hex modulus = " & hexModulus) & "</pre>"

' Now get the modulus from the cert:
set cert = Server.CreateObject("Chilkat.Cert")

success = cert.LoadFromFile("qa_data/certs/test_12345678a.cer")
If (success = 0) Then
    Response.Write "<pre>" & Server.HTMLEncode( cert.LastErrorText) & "</pre>"
    Response.End
End If

' The cert contains the public key, which is composed of the
' modulus + exponent (for RSA keys).
set pubKey = Server.CreateObject("Chilkat.PublicKey")
success = cert.GetPublicKey(pubKey)

success = xml.LoadXml(pubKey.GetXml())
Response.Write "<pre>" & Server.HTMLEncode( "Public Key XML:") & "</pre>"
Response.Write "<pre>" & Server.HTMLEncode( xml.GetXml()) & "</pre>"

' Proceed in the same way as before....
modulus = xml.GetChildContent("Modulus")
Response.Write "<pre>" & Server.HTMLEncode( "base64 modulus = " & modulus) & "</pre>"

' To convert to hex:
success = binDat.Clear()
success = binDat.AppendEncoded(modulus,"base64")
hexModulus = binDat.GetEncoded("hex")
Response.Write "<pre>" & Server.HTMLEncode( "hex modulus = " & hexModulus) & "</pre>"

%>
</body>
</html>