Lua Requires Chilkat v11.0.0+
Lua
RSA Sign using Base64 Private Key
See more RSA Examples
Signs a string using a non-encrypted RSA private key in base64 encoding. Returns the RSA signature as a base64 string.Chilkat Lua Downloads
local chilkat = require("chilkat")
-- This requires the Chilkat API to have been previously unlocked.
-- See Global Unlock Sample for sample code.
local privKey = chilkat.PrivateKey.new()
local sbPem = chilkat.StringBuilder.new()
sbPem:append_line("-----BEGIN RSA PRIVATE KEY-----", true)
sbPem:append_line("MIIC .... j5A==", true)
sbPem:append_line("-----END RSA PRIVATE KEY-----", true)
local success = privKey:load_pem(sbPem:get_as_string())
if not success then
print(privKey.last_error_text)
return
end
local rsa = chilkat.Rsa.new()
success = rsa:use_private_key(privKey)
if not success then
print(rsa.last_error_text)
return
end
local bd = chilkat.BinData.new()
bd:append_string("12345678", "utf-8")
success = rsa:sign_raw_bd(bd)
if not success then
print(rsa.last_error_text)
return
end
-- Get the base64 RSA signature.
print(bd:get_encoded("base64"))
success = rsa:verify_raw_bd(bd)
if not success then
print(rsa.last_error_text)
return
end
local strOriginal = bd:get_string("utf-8")
print(strOriginal)