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

Duplicate openssl pkey -in private.pem -pubout -out pubkey.pem

See more OpenSSL Examples

How to output the public part of a private key: Demonstrates how to duplicate this OpenSSL command:
openssl pkey -in private.pem -pubout -out pubkey.pem

Chilkat Lua Downloads

Lua
local chilkat = require("chilkat")

local pkey = chilkat.PrivateKey.new()

-- Load the private key from an PEM file:
local success = pkey:load_pem_file("private.pem")
if not success then
    print(pkey.last_error_text)
    return
end

local pubKey = chilkat.PublicKey.new()
pkey:to_public_key(pubKey)

success = pubKey:save_pem_file(false, "pubKey.pem")
if not success then
    print(pubKey.last_error_text)

    return
end

print("Success.")