(PureBasic) RSA Import Private Key
Shows how to select/import a private key for RSA signing or decryption.
IncludeFile "CkPrivateKey.pb"
IncludeFile "CkRsa.pb"
Procedure ChilkatExample()
privKey.i = CkPrivateKey::ckCreate()
If privKey.i = 0
Debug "Failed to create object."
ProcedureReturn
EndIf
password.s = "secret"
; In all Chilkat methods expecting a path, you pass either absolute or relative paths.
success.i = CkPrivateKey::ckLoadAnyFormatFile(privKey,"rsaKeys/myTestRsaPrivate.pem",password)
If success = 0
Debug CkPrivateKey::ckLastErrorText(privKey)
CkPrivateKey::ckDispose(privKey)
ProcedureReturn
EndIf
rsa.i = CkRsa::ckCreate()
If rsa.i = 0
Debug "Failed to create object."
ProcedureReturn
EndIf
; Tell the RSA object to use the private key (i.e. import the private key)
CkRsa::ckImportPrivateKeyObj(rsa,privKey)
CkPrivateKey::ckDispose(privKey)
CkRsa::ckDispose(rsa)
ProcedureReturn
EndProcedure
|