AutoIt
AutoIt
Get a Certificate's Key Size
See more Certificates Examples
Demonstrates how to get the RSA key size of a certificate (for example, 1024-bit, 2048-bit, etc.)Chilkat AutoIt Downloads
Local $bSuccess = False
; For this example, I have a certificate in raw base64 format (not PEM),
; that looks like this: "MIIGkDCCBHigAwIBAgIUMDA ... s/iqLsLA=="
$oSbCertBase64 = ObjCreate("Chilkat.StringBuilder")
$bSuccess = $oSbCertBase64.LoadFile("qa_data/certs/base64Cert.txt","utf-8")
$oCert = ObjCreate("Chilkat.Cert")
$bSuccess = $oCert.LoadFromBase64($oSbCertBase64.GetAsString())
If ($bSuccess = False) Then
ConsoleWrite($oCert.LastErrorText & @CRLF)
Exit
EndIf
; Get the public key.
$oPubKey = ObjCreate("Chilkat.PublicKey")
$oCert.GetPublicKey($oPubKey)
Local $iNumBits = $oPubKey.KeySize
ConsoleWrite("Number of bits = " & $iNumBits & @CRLF)
; If using an older version of Chilkat, the key size can be obtained like this:
$oXml = ObjCreate("Chilkat.Xml")
$oXml.LoadXml($oPubKey.GetXml())
$oBinDat = ObjCreate("Chilkat.BinData")
$oBinDat.AppendEncoded($oXml.GetChildContent("Modulus"),"base64")
$iNumBits = 8 * $oBinDat.NumBytes
ConsoleWrite("Number of bits = " & $iNumBits & @CRLF)