(Tcl) RSA Import Public Key from Certificate PEM
Uses a certificate's public key for RSA encryption. The public key from the certificate .pem file is used.
load ./chilkat.dll
set cert [new_CkCert]
set success [CkCert_LoadFromFile $cert "qa_data/pem/mf_public_rsa.pem"]
if {$success == 0} then {
puts [CkCert_lastErrorText $cert]
delete_CkCert $cert
exit
}
# pubKey is a CkPublicKey
set pubKey [CkCert_ExportPublicKey $cert]
if {[CkCert_get_LastMethodSuccess $cert] != 1} then {
puts [CkCert_lastErrorText $cert]
delete_CkCert $cert
exit
}
set rsa [new_CkRsa]
set success [CkRsa_ImportPublicKeyObj $rsa $pubKey]
if {$success == 0} then {
puts [CkRsa_lastErrorText $rsa]
delete_CkCert $cert
delete_CkRsa $rsa
exit
}
delete_CkPublicKey $pubKey
CkRsa_put_EncodingMode $rsa "base64"
set encryptedStr [CkRsa_encryptStringENC $rsa "hello" 0]
puts "encrypted string = $encryptedStr"
delete_CkCert $cert
delete_CkRsa $rsa
|