Sample code for 30+ languages & platforms
Lua Requires Chilkat v11.0.0+

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 Lua Downloads

Lua
local chilkat = require("chilkat")

-- This example requires the Chilkat API to have been previously unlocked.
-- See Global Unlock Sample for sample code.

local pubkey = chilkat.PublicKey.new()

local success = pubkey:load_base64("MIICdgIBADA ... A9PXLk+j5A==")
if not success then
    print(pubkey.last_error_text)
    return
end

local rsa = chilkat.Rsa.new()

success = rsa:use_public_key(pubkey)
if not success then
    print(rsa.last_error_text)
    return
end

rsa.encoding_mode = "base64"

local encryptedStr = rsa:encrypt_string_enc("12345678", false)

print(encryptedStr)