Sample code for 30+ languages & platforms
AutoIt

Export Digital Certificate's Public Key

See more Certificates Examples

The ExportPublicKey method can be called to get a certificate's public key. It can then be saved to any of a number of formats: (1) OpenSSL DER, (2) OpenSSL PEM, (3) RSA DER, (4) XML.

Chilkat AutoIt Downloads

AutoIt
Local $bSuccess = False

$oCert = ObjCreate("Chilkat.Cert")

; LoadFromFile will load virtually any certificate format file.
; It will auto-recognize the format and load appropiately.
$bSuccess = $oCert.LoadFromFile("/Users/chilkat/testData/cer/chilkat.cer")
If ($bSuccess = False) Then
    ConsoleWrite($oCert.LastErrorText & @CRLF)
    Exit
EndIf

; Get the public key:
$oPubkey = ObjCreate("Chilkat.PublicKey")
$oCert.GetPublicKey($oPubkey)

; Save to various formats:
$bSuccess = $oPubkey.SaveDerFile(False,"/Users/chilkat/testData/pubkeys/chilkat_pkcs8.der")
If ($bSuccess <> True) Then
    ConsoleWrite($oPubkey.LastErrorText & @CRLF)
    Exit
EndIf

$bSuccess = $oPubkey.SavePemFile(False,"/Users/chilkat/testData/pubkeys/chilkat.pem")
If ($bSuccess <> True) Then
    ConsoleWrite($oPubkey.LastErrorText & @CRLF)
    Exit
EndIf

$bSuccess = $oPubkey.SaveDerFile(True,"/Users/chilkat/testData/pubkeys/chilkat_pkcs1.der")
If ($bSuccess <> True) Then
    ConsoleWrite($oPubkey.LastErrorText & @CRLF)
    Exit
EndIf

$bSuccess = $oPubkey.SaveXmlFile("/Users/chilkat/testData/pubkeys/chilkat.xml")
If ($bSuccess <> True) Then
    ConsoleWrite($oPubkey.LastErrorText & @CRLF)
    Exit
EndIf

ConsoleWrite("Public key exported to all file formats." & @CRLF)