Sample code for 30+ languages & platforms
Xbase++

Convert DSA DER Private Key to PEM

See more DSA Examples

Converts a DSA private key from DER format to PEM. Demonstrates how to write both encrypted and unencrypted PEM formatted private keys.

Chilkat Xbase++ Downloads

Xbase++
LOCAL nSuccess
LOCAL oDsa
LOCAL cPemStr

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 DER private key.
nSuccess := oDsa:FromDerFile("dsa_priv.der")
IF (nSuccess != 1)
    ? oDsa:LastErrorText
    oDsa:destroy()
    RETURN
ENDIF

//  Save to unencrypted PEM:
cPemStr := oDsa:ToPem()
nSuccess := oDsa:SaveText(cPemStr, "dsa_priv.pem")
IF (nSuccess != 1)
    ? oDsa:LastErrorText
    oDsa:destroy()
    RETURN
ENDIF

//  Save to encrypted PEM:
cPemStr := oDsa:ToEncryptedPem("myPassword")
nSuccess := oDsa:SaveText(cPemStr, "dsa_privEncrypted.pem")
IF (nSuccess != 1)
    ? oDsa:LastErrorText
    oDsa:destroy()
    RETURN
ENDIF

? "Finished!"

oDsa:destroy()