Tcl
Tcl
Load Identities from PEM Text
See more PFX/P12 Examples
Demonstrates Pfx.LoadPem, which loads one or more certificate/private-key identities from PEM-formatted text and builds the contents of the Pfx object.
The file path is relative to the application's current working directory. An absolute path may also be used. Supply the path appropriate to your own environment.
Background. The password decrypts any encrypted private keys in the PEM. This builds a PFX in memory from PEM material, which can then be serialized to PKCS#12.
Chilkat Tcl Downloads
load ./chilkat.dll
set success 0
set pfx [new_CkPfx]
# The file path is relative to the application's current working directory. An absolute path
# may also be used. Supply the path appropriate to your own environment.
# Load the PEM text (certificates and private keys) into a string.
set sbPem [new_CkStringBuilder]
set bLoaded [CkStringBuilder_LoadFile $sbPem "qa_data/identity.pem"]
if {$bLoaded != 1} then {
puts "Failed to load the PEM file."
delete_CkPfx $pfx
delete_CkStringBuilder $sbPem
exit
}
set pemText [CkStringBuilder_getAsString $sbPem]
if {[CkStringBuilder_get_LastMethodSuccess $sbPem] == 0} then {
puts [CkStringBuilder_lastErrorText $sbPem]
delete_CkPfx $pfx
delete_CkStringBuilder $sbPem
exit
}
# The password decrypts any encrypted private keys in the PEM (use an empty string if none are
# encrypted). A password should come from a secure source rather than being hard-coded.
set password "myPemPassword"
set success [CkPfx_LoadPem $pfx $pemText $password]
if {$success == 0} then {
puts [CkPfx_lastErrorText $pfx]
delete_CkPfx $pfx
delete_CkStringBuilder $sbPem
exit
}
puts "Loaded [CkPfx_get_NumPrivateKeys $pfx] private key(s)."
delete_CkPfx $pfx
delete_CkStringBuilder $sbPem