Unicode C
Unicode C
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 Unicode C Downloads
#include <C_CkPublicKeyW.h>
#include <C_CkBinDataW.h>
#include <C_CkRsaW.h>
void ChilkatSample(void)
{
BOOL success;
HCkPublicKeyW pubKey;
HCkBinDataW bdFileData;
HCkBinDataW bdSig;
HCkRsaW rsa;
success = FALSE;
// This example requires the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
pubKey = CkPublicKeyW_Create();
// Load the public key from an PEM file:
success = CkPublicKeyW_LoadFromFile(pubKey,L"pubKey.pem");
if (success == FALSE) {
wprintf(L"%s\n",CkPublicKeyW_lastErrorText(pubKey));
CkPublicKeyW_Dispose(pubKey);
return;
}
// Load the data of the original file that was signed.
bdFileData = CkBinDataW_Create();
success = CkBinDataW_LoadFile(bdFileData,L"in.dat");
// Load the signature.
bdSig = CkBinDataW_Create();
success = CkBinDataW_LoadFile(bdSig,L"signature.sig");
rsa = CkRsaW_Create();
// Import the public key into the RSA component:
success = CkRsaW_UsePublicKey(rsa,pubKey);
if (success == FALSE) {
wprintf(L"%s\n",CkRsaW_lastErrorText(rsa));
CkPublicKeyW_Dispose(pubKey);
CkBinDataW_Dispose(bdFileData);
CkBinDataW_Dispose(bdSig);
CkRsaW_Dispose(rsa);
return;
}
// OpenSSL uses big-endian.
CkRsaW_putLittleEndian(rsa,FALSE);
success = CkRsaW_VerifyBd(rsa,bdFileData,L"sha256",bdSig);
if (success != TRUE) {
wprintf(L"%s\n",CkRsaW_lastErrorText(rsa));
wprintf(L"The signature was invalid.\n");
CkPublicKeyW_Dispose(pubKey);
CkBinDataW_Dispose(bdFileData);
CkBinDataW_Dispose(bdSig);
CkRsaW_Dispose(rsa);
return;
}
wprintf(L"The signature was verified.\n");
CkPublicKeyW_Dispose(pubKey);
CkBinDataW_Dispose(bdFileData);
CkBinDataW_Dispose(bdSig);
CkRsaW_Dispose(rsa);
}