Sample code for 30+ languages & platforms
Xbase++

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 Xbase++ Downloads

Xbase++
LOCAL nSuccess
LOCAL oPrivKey
LOCAL cPassword
LOCAL oXml
LOCAL cModulus
LOCAL oBinDat
LOCAL cHexModulus
LOCAL oCert
LOCAL oPubKey

nSuccess := 0

oPrivKey := CreateObject("Chilkat.PrivateKey")

cPassword := "12345678a"
nSuccess := oPrivKey:LoadPkcs8EncryptedFile("qa_data/certs/test_12345678a.key", cPassword)
IF (nSuccess == 0)
    ? oPrivKey:LastErrorText
    oPrivKey:destroy()
    RETURN
ENDIF

oXml := CreateObject("Chilkat.Xml")
oXml:LoadXml(oPrivKey:GetXml())

//  The XML contains the parts of the key in base64.
? "Private Key XML:"
? oXml:GetXml()

//  We can get the base64 modulus like this:
cModulus := oXml:GetChildContent("Modulus")
? "base64 modulus = " + cModulus

//  To convert to hex:
oBinDat := CreateObject("Chilkat.BinData")
oBinDat:AppendEncoded(cModulus, "base64")
cHexModulus := oBinDat:GetEncoded("hex")
? "hex modulus = " + cHexModulus

//  Now get the modulus from the cert:
oCert := CreateObject("Chilkat.Cert")

nSuccess := oCert:LoadFromFile("qa_data/certs/test_12345678a.cer")
IF (nSuccess == 0)
    ? oCert:LastErrorText
    oPrivKey:destroy()
    oXml:destroy()
    oBinDat:destroy()
    oCert:destroy()
    RETURN
ENDIF

//  The cert contains the public key, which is composed of the
//  modulus + exponent (for RSA keys).
oPubKey := CreateObject("Chilkat.PublicKey")
oCert:GetPublicKey(oPubKey)

oXml:LoadXml(oPubKey:GetXml())
? "Public Key XML:"
? oXml:GetXml()

//  Proceed in the same way as before....
cModulus := oXml:GetChildContent("Modulus")
? "base64 modulus = " + cModulus

//  To convert to hex:
oBinDat:Clear()
oBinDat:AppendEncoded(cModulus, "base64")
cHexModulus := oBinDat:GetEncoded("hex")
? "hex modulus = " + cHexModulus

oPrivKey:destroy()
oXml:destroy()
oBinDat:destroy()
oCert:destroy()
oPubKey:destroy()