Sample code for 30+ languages & platforms
PureBasic

Convert Certificate from DER to PEM.

See more Certificates Examples

Loads a digital certificate from any format, such as DER, and saves to PEM format.

Chilkat PureBasic Downloads

PureBasic
IncludeFile "CkCert.pb"

Procedure ChilkatExample()

    success.i = 0

    cert.i = CkCert::ckCreate()
    If cert.i = 0
        Debug "Failed to create object."
        ProcedureReturn
    EndIf

    ; LoadFromFile will load virtually any certificate format file.
    ; It will auto-recognize the format and load appropiately.
    ; In this case, load a DER format certificate and convert to PEM.
    success = CkCert::ckLoadFromFile(cert,"qa_data/certs/testCert.cer")
    If success <> 1
        Debug CkCert::ckLastErrorText(cert)
        CkCert::ckDispose(cert)
        ProcedureReturn
    EndIf

    success = CkCert::ckExportCertPemFile(cert,"qa_data/certs/testCert.pem")
    If success <> 1
        Debug CkCert::ckLastErrorText(cert)
        CkCert::ckDispose(cert)
        ProcedureReturn
    EndIf

    Debug "Converted certificate from DER to PEM format."


    CkCert::ckDispose(cert)


    ProcedureReturn
EndProcedure