Sample code for 30+ languages & platforms
Java

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 Java Downloads

Chilkat2 Java
import com.chilkatsoft.chilkat2.ChilkatException;
import com.chilkatsoft.chilkat2.Dsa;

public class ChilkatExample {

    public static void main(String[] args) {
        // This example requires the Chilkat API to have been previously unlocked.
        // See Global Unlock Sample for sample code.

        Dsa dsa = new Dsa();

        // Load a DER private key.
        try {
            dsa.fromDerFile("dsa_priv.der");
        } catch (ChilkatException e) {
            System.out.println(e.getLastErrorText());
            return;
        }

        // Save to unencrypted PEM:
        String pemStr = dsa.toPem();
        try {
            dsa.saveText(pemStr, "dsa_priv.pem");

            // Save to encrypted PEM:
            pemStr = dsa.toEncryptedPem("myPassword");
            dsa.saveText(pemStr, "dsa_privEncrypted.pem");
        } catch (ChilkatException e) {
            System.out.println(e.getLastErrorText());
            return;
        }

        System.out.println("Finished!");
    }
}