Xbase++ Requires Chilkat v11.0.0+
Xbase++
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.datThe 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:
- Creates a SHA256 digest of the contents of the input file.
- Verifies the SHA256 digest using the public key.
Chilkat Xbase++ Downloads
LOCAL nSuccess
LOCAL oPubKey
LOCAL oBdFileData
LOCAL oBdSig
LOCAL oRsa
nSuccess := 0
// This example requires the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
oPubKey := CreateObject("Chilkat.PublicKey")
// Load the public key from an PEM file:
nSuccess := oPubKey:LoadFromFile("pubKey.pem")
IF (nSuccess == 0)
? oPubKey:LastErrorText
oPubKey:destroy()
RETURN
ENDIF
// Load the data of the original file that was signed.
oBdFileData := CreateObject("Chilkat.BinData")
nSuccess := oBdFileData:LoadFile("in.dat")
// Load the signature.
oBdSig := CreateObject("Chilkat.BinData")
nSuccess := oBdSig:LoadFile("signature.sig")
oRsa := CreateObject("Chilkat.Rsa")
// Import the public key into the RSA component:
nSuccess := oRsa:UsePublicKey(oPubKey)
IF (nSuccess == 0)
? oRsa:LastErrorText
oPubKey:destroy()
oBdFileData:destroy()
oBdSig:destroy()
oRsa:destroy()
RETURN
ENDIF
// OpenSSL uses big-endian.
oRsa:LittleEndian := 0
nSuccess := oRsa:VerifyBd(oBdFileData, "sha256", oBdSig)
IF (nSuccess != 1)
? oRsa:LastErrorText
? "The signature was invalid."
oPubKey:destroy()
oBdFileData:destroy()
oBdSig:destroy()
oRsa:destroy()
RETURN
ENDIF
? "The signature was verified."
oPubKey:destroy()
oBdFileData:destroy()
oBdSig:destroy()
oRsa:destroy()