Sample code for 30+ languages & platforms
Xbase++

Convert DSA PEM Private Key to DER

See more DSA Examples

Converts a DSA private key from PEM format to DER. The first part of the example will convert an unencrypted PEM to DER, then 2nd part will convert an encrypted PEM to unencrypted DER.

Chilkat Xbase++ Downloads

Xbase++
LOCAL nSuccess
LOCAL oDsa
LOCAL cPemPrivateKey

nSuccess := 0

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

oDsa := CreateObject("Chilkat.Dsa")

//  Load a PEM private key.

cPemPrivateKey := oDsa:LoadText("dsa_priv.pem")
//  Import the unencrypted PEM into the DSA object.
nSuccess := oDsa:FromPem(cPemPrivateKey)
IF (nSuccess != 1)
    ? oDsa:LastErrorText
    oDsa:destroy()
    RETURN
ENDIF

//  Write it out as a DER file:
nSuccess := oDsa:ToDerFile("dsa_priv.der")
IF (nSuccess != 1)
    ? oDsa:LastErrorText
    oDsa:destroy()
    RETURN
ENDIF

//  Load an encrypted PEM private key.
cPemPrivateKey := oDsa:LoadText("dsa_privEncrypted.pem")
//  Import the encrypted PEM into the DSA object.
nSuccess := oDsa:FromEncryptedPem("myPassword", cPemPrivateKey)
IF (nSuccess != 1)
    ? oDsa:LastErrorText
    oDsa:destroy()
    RETURN
ENDIF

//  Write it out as an unencrypted DER file:
nSuccess := oDsa:ToDerFile("dsa_priv2.der")
IF (nSuccess != 1)
    ? oDsa:LastErrorText
    oDsa:destroy()
    RETURN
ENDIF

? "Finished!"

oDsa:destroy()