(PureBasic) Use Base64 RSA Key to Encrypt
Loads a Base64 RSA key and uses it to encrypt a string, returning the result in base64.
IncludeFile "CkPublicKey.pb"
IncludeFile "CkRsa.pb"
Procedure ChilkatExample()
; This example requires the Chilkat API to have been previously unlocked.
; See Global Unlock Sample for sample code.
pubkey.i = CkPublicKey::ckCreate()
If pubkey.i = 0
Debug "Failed to create object."
ProcedureReturn
EndIf
success.i = CkPublicKey::ckLoadBase64(pubkey,"MIICdgIBADA ... A9PXLk+j5A==")
If success <> 1
Debug CkPublicKey::ckLastErrorText(pubkey)
CkPublicKey::ckDispose(pubkey)
ProcedureReturn
EndIf
rsa.i = CkRsa::ckCreate()
If rsa.i = 0
Debug "Failed to create object."
ProcedureReturn
EndIf
success = CkRsa::ckImportPublicKeyObj(rsa,pubkey)
If success <> 1
Debug CkRsa::ckLastErrorText(rsa)
CkPublicKey::ckDispose(pubkey)
CkRsa::ckDispose(rsa)
ProcedureReturn
EndIf
CkRsa::setCkEncodingMode(rsa, "base64")
encryptedStr.s = CkRsa::ckEncryptStringENC(rsa,"12345678",0)
Debug encryptedStr
CkPublicKey::ckDispose(pubkey)
CkRsa::ckDispose(rsa)
ProcedureReturn
EndProcedure
|