(Tcl) Convert DSA DER Private Key to PEM
Converts a DSA private key from DER format to PEM. Demonstrates how to write both encrypted and unencrypted PEM formatted private keys.
load ./chilkat.dll
# This example requires the Chilkat API to have been previously unlocked.
# See Global Unlock Sample for sample code.
set dsa [new_CkDsa]
# Load a DER private key.
set success [CkDsa_FromDerFile $dsa "dsa_priv.der"]
if {$success != 1} then {
puts [CkDsa_lastErrorText $dsa]
delete_CkDsa $dsa
exit
}
# Save to unencrypted PEM:
set pemStr [CkDsa_toPem $dsa]
set success [CkDsa_SaveText $dsa $pemStr "dsa_priv.pem"]
if {$success != 1} then {
puts [CkDsa_lastErrorText $dsa]
delete_CkDsa $dsa
exit
}
# Save to encrypted PEM:
set pemStr [CkDsa_toEncryptedPem $dsa "myPassword"]
set success [CkDsa_SaveText $dsa $pemStr "dsa_privEncrypted.pem"]
if {$success != 1} then {
puts [CkDsa_lastErrorText $dsa]
delete_CkDsa $dsa
exit
}
puts "Finished!"
delete_CkDsa $dsa
|