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

Duplicate openssl dgst -sha256 -verify pubKey.pem -signature signature.sig in.dat

See more OpenSSL Examples

Demonstrates how to duplicate this OpenSSL command:
openssl dgst -sha256 -verify pubKey.pem -signature signature.sig in.dat
The in.dat file contains the original data that was signed, and can contain text or binary data of any type. The above OpenSSL command does the following:
  1. Creates a SHA256 digest of the contents of the input file.
  2. Verifies the SHA256 digest using the public key.

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()

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

-- Load the data of the original file that was signed.
local bdFileData = chilkat.BinData.new()
success = bdFileData:load_file("in.dat")

-- Load the signature.
local bdSig = chilkat.BinData.new()
success = bdSig:load_file("signature.sig")

local rsa = chilkat.Rsa.new()

-- Import the public key into the RSA component:
success = rsa:use_public_key(pubKey)
if not success then
    print(rsa.last_error_text)
    return
end

-- OpenSSL uses big-endian.
rsa.little_endian = false

success = rsa:verify_bd(bdFileData, "sha256", bdSig)
if not success then
    print(rsa.last_error_text)
    print("The signature was invalid.")
    return
end

print("The signature was verified.")