Tcl
Tcl
RSA Sign Using Private Key from .pfx/.p12 to Base64 Signature
See more RSA Examples
Demonstrates how to RSA sign something using a private key loaded from a .pfx/.p12. The RSA signature is returned in Base64 encoded format.Chilkat Tcl Downloads
load ./chilkat.dll
set success 0
# This example assumes the Chilkat API to have been previously unlocked.
# See Global Unlock Sample for sample code.
set rsa [new_CkRsa]
# Load the .pfx/.p12
set pfx [new_CkPfx]
set success [CkPfx_LoadPfxFile $pfx "qa_data/pfx/myKey.p12" "myPassword"]
if {$success == 0} then {
puts [CkPfx_lastErrorText $pfx]
delete_CkRsa $rsa
delete_CkPfx $pfx
exit
}
# Get the default private key.
set privKey [new_CkPrivateKey]
set success [CkPfx_PrivateKeyAt $pfx 0 $privKey]
if {$success == 0} then {
puts [CkPfx_lastErrorText $pfx]
delete_CkRsa $rsa
delete_CkPfx $pfx
delete_CkPrivateKey $privKey
exit
}
# Import the private key into the RSA component:
set success [CkRsa_UsePrivateKey $rsa $privKey]
if {$success == 0} then {
puts [CkRsa_lastErrorText $rsa]
delete_CkRsa $rsa
delete_CkPfx $pfx
delete_CkPrivateKey $privKey
exit
}
# Get the signature in base64
CkRsa_put_EncodingMode $rsa "base64"
set strData "This is the string to be signed."
# Sign the string using the sha256 hash algorithm.
# Other valid choices are "sha384", "sha512", "sha-1", "md2" and "md5".
set base64Sig [CkRsa_signStringENC $rsa $strData "sha256"]
puts "$base64Sig"
puts "Success!"
delete_CkRsa $rsa
delete_CkPfx $pfx
delete_CkPrivateKey $privKey