Visual FoxPro
Visual FoxPro
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 -nooutor
openssl pkcs8 -inform DER -inβ "test.key"β -outform PEM -passin pass:"12345β678aβ" | openssl rsa -inform PEM -modulus -noout
Chilkat Visual FoxPro Downloads
LOCAL lnSuccess
LOCAL loPrivKey
LOCAL lcPassword
LOCAL loXml
LOCAL lcModulus
LOCAL loBinDat
LOCAL lcHexModulus
LOCAL loCert
LOCAL loPubKey
lnSuccess = 0
loPrivKey = CreateObject('Chilkat.PrivateKey')
lcPassword = "12345678a"
lnSuccess = loPrivKey.LoadPkcs8EncryptedFile("qa_data/certs/test_12345678a.key",lcPassword)
IF (lnSuccess = 0) THEN
? loPrivKey.LastErrorText
RELEASE loPrivKey
CANCEL
ENDIF
loXml = CreateObject('Chilkat.Xml')
loXml.LoadXml(loPrivKey.GetXml())
* The XML contains the parts of the key in base64.
? "Private Key XML:"
? loXml.GetXml()
* We can get the base64 modulus like this:
lcModulus = loXml.GetChildContent("Modulus")
? "base64 modulus = " + lcModulus
* To convert to hex:
loBinDat = CreateObject('Chilkat.BinData')
loBinDat.AppendEncoded(lcModulus,"base64")
lcHexModulus = loBinDat.GetEncoded("hex")
? "hex modulus = " + lcHexModulus
* Now get the modulus from the cert:
loCert = CreateObject('Chilkat.Cert')
lnSuccess = loCert.LoadFromFile("qa_data/certs/test_12345678a.cer")
IF (lnSuccess = 0) THEN
? loCert.LastErrorText
RELEASE loPrivKey
RELEASE loXml
RELEASE loBinDat
RELEASE loCert
CANCEL
ENDIF
* The cert contains the public key, which is composed of the
* modulus + exponent (for RSA keys).
loPubKey = CreateObject('Chilkat.PublicKey')
loCert.GetPublicKey(loPubKey)
loXml.LoadXml(loPubKey.GetXml())
? "Public Key XML:"
? loXml.GetXml()
* Proceed in the same way as before....
lcModulus = loXml.GetChildContent("Modulus")
? "base64 modulus = " + lcModulus
* To convert to hex:
loBinDat.Clear()
loBinDat.AppendEncoded(lcModulus,"base64")
lcHexModulus = loBinDat.GetEncoded("hex")
? "hex modulus = " + lcHexModulus
RELEASE loPrivKey
RELEASE loXml
RELEASE loBinDat
RELEASE loCert
RELEASE loPubKey