Sample code for 30+ languages & platforms
Lua

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

Lua
local chilkat = require("chilkat")

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

local dsa = chilkat.Dsa.new()

-- Load a DER private key.
local success = dsa:from_der_file("dsa_priv.der")
if not success then
    print(dsa.last_error_text)
    return
end

-- Save to unencrypted PEM:
local pemStr = dsa:to_pem()
success = dsa:save_text(pemStr, "dsa_priv.pem")
if not success then
    print(dsa.last_error_text)
    return
end

-- Save to encrypted PEM:
pemStr = dsa:to_encrypted_pem("myPassword")
success = dsa:save_text(pemStr, "dsa_privEncrypted.pem")
if not success then
    print(dsa.last_error_text)
    return
end

print("Finished!")