Sample code for 30+ languages & platforms
PureBasic

Use Base64 RSA Key to Encrypt

See more RSA Examples

Loads a Base64 RSA key and uses it to encrypt a string, returning the result in base64.

Chilkat PureBasic Downloads

PureBasic
IncludeFile "CkPublicKey.pb"
IncludeFile "CkRsa.pb"

Procedure ChilkatExample()

    success.i = 0

    ; 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 = CkPublicKey::ckLoadBase64(pubkey,"MIICdgIBADA ... A9PXLk+j5A==")
    If success = 0
        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::ckUsePublicKey(rsa,pubkey)
    If success = 0
        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