Lua Requires Chilkat v11.0.0+
Lua
Generate RSA Key and return Base64 PKCS8 Private Key
See more RSA Examples
Demonstrates how to generate a new 2048-bit RSA private key and returns the Base64 encoded PKCS8 representation of the private key.Chilkat Lua Downloads
local chilkat = require("chilkat")
local rsa = chilkat.Rsa.new()
-- Generate a 2048-bit key. Chilkat RSA supports
-- key sizes ranging from 512 bits to 8192 bits.
local privKey = chilkat.PrivateKey.new()
local success = rsa:gen_key(2048, privKey)
if not success then
print(rsa.last_error_text)
return
end
-- Get the private key in PKCS8 Base64 format
local privKeyPkcs8Base64 = privKey:get_pkcs8_enc("base64")
-- The key in base64 format will start similar to this:
-- MIIEvAIBADANBgkqhkiG9w0BA...
print(privKeyPkcs8Base64)