Sample code for 30+ languages & platforms
PureBasic

DSA Public Key PEM to DER Conversion

See more DSA Examples

Converts a DSA public key from PEM format to DER.

Chilkat PureBasic Downloads

PureBasic
IncludeFile "CkDsa.pb"

Procedure ChilkatExample()

    success.i = 0

    ; This example requires the Chilkat API to have been previously unlocked.
    ; See Global Unlock Sample for sample code.

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

    ; Load a PEM public key.
    pemPublicKey.s
    pemPublicKey = CkDsa::ckLoadText(dsa,"dsa_pub.pem")
    ; Import the public key PEM into the DSA object.
    success = CkDsa::ckFromPublicPem(dsa,pemPublicKey)
    If success <> 1
        Debug CkDsa::ckLastErrorText(dsa)
        CkDsa::ckDispose(dsa)
        ProcedureReturn
    EndIf

    ; Write it out as a DER file:
    success = CkDsa::ckToPublicDerFile(dsa,"dsa_pub.der")
    If success <> 1
        Debug CkDsa::ckLastErrorText(dsa)
        CkDsa::ckDispose(dsa)
        ProcedureReturn
    EndIf

    Debug "Finished!"


    CkDsa::ckDispose(dsa)


    ProcedureReturn
EndProcedure