(Tcl) Duplicate openssl pkey -in private.pem -pubout -out pubkey.pem
How to output the public part of a private key:
Demonstrates how to duplicate this OpenSSL command:
openssl pkey -in private.pem -pubout -out pubkey.pem
load ./chilkat.dll
set pkey [new_CkPrivateKey]
# Load the private key from an PEM file:
set success [CkPrivateKey_LoadPemFile $pkey "private.pem"]
if {$success != 1} then {
puts [CkPrivateKey_lastErrorText $pkey]
delete_CkPrivateKey $pkey
exit
}
# pubKey is a CkPublicKey
set pubKey [CkPrivateKey_GetPublicKey $pkey]
if {[CkPrivateKey_get_LastMethodSuccess $pkey] == 0} then {
puts [CkPrivateKey_lastErrorText $pkey]
delete_CkPrivateKey $pkey
exit
}
set success [CkPublicKey_SavePemFile $pubKey 0 "pubKey.pem"]
if {$success != 1} then {
puts [CkPublicKey_lastErrorText $pubKey]
delete_CkPublicKey $pubKey
delete_CkPrivateKey $pkey
exit
}
puts "Success."
delete_CkPublicKey $pubKey
delete_CkPrivateKey $pkey
|