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

RSASSA-PSS Algorithm with SHA256 Hashing

See more RSA Examples

RSA encrypt a SHA256 hash with OAEP padding.

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 privkey = chilkat.PrivateKey.new()

-- Load the private key object from a PEM file.
-- (To load from a PEM string, call LoadPem instead.)
local success = privkey:load_pem_file("somePath/myPrivateKey.pem")
if not success then
    print(privkey.last_error_text)
    return
end

local rsa = chilkat.Rsa.new()
-- Use RSA-PSS by setting PkcsPadding = false
rsa.pkcs_padding = false
-- Use SHA256
rsa.oaep_hash = "SHA-256"

rsa:use_private_key(privkey)

-- Generate a base64 signature.
rsa.encoding_mode = "base64"

local sigStr = rsa:sign_string_enc("String to be signed", "SHA-256")
if not rsa.last_method_success then
    print(rsa.last_error_text)
    return
end

print("Signature: " .. sigStr)