Chilkat HOME .NET Core C# Android™ AutoIt C C# C++ Chilkat2-Python CkPython Classic ASP DataFlex Delphi ActiveX Delphi DLL Go Java Lianja Mono C# Node.js Objective-C PHP ActiveX PHP Extension Perl PowerBuilder PowerShell PureBasic Ruby SQL Server Swift 2 Swift 3,4,5... Tcl Unicode C Unicode C++ VB.NET VBScript Visual Basic 6.0 Visual FoxPro Xojo Plugin
(Unicode C) Duplicate openssl dgst -sha256 -verify pubKey.pem -signature signature.sig in.datDemonstrates 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:
#include <C_CkPublicKeyW.h> #include <C_CkBinDataW.h> #include <C_CkRsaW.h> void ChilkatSample(void) { HCkPublicKeyW pubKey; BOOL success; HCkBinDataW bdFileData; HCkBinDataW bdSig; HCkRsaW rsa; // 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 != TRUE) { 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_ImportPublicKeyObj(rsa,pubKey); if (success != TRUE) { 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); } |
© 2000-2024 Chilkat Software, Inc. All Rights Reserved.