Chilkat HOME Android™ AutoIt C C# C++ Chilkat2-Python CkPython Classic ASP DataFlex Delphi DLL Go Java Node.js Objective-C PHP Extension Perl PowerBuilder PowerShell PureBasic Ruby SQL Server Swift Tcl Unicode C Unicode C++ VB.NET VBScript Visual Basic 6.0 Visual FoxPro Xojo Plugin
(Unicode C) Verfies an RSA SignatureSee more Apple Keychain ExamplesVerifies an RSA signature against the original data.
#include <C_CkBinDataW.h> #include <C_CkPublicKeyW.h> #include <C_CkRsaW.h> void ChilkatSample(void) { HCkBinDataW bd; int i; HCkBinDataW bdSig; BOOL success; HCkPublicKeyW pubKey; HCkRsaW rsa; // The following data was signed by the following example: // RSA Sign using a Private Key on a USB Token or Smartcard bd = CkBinDataW_Create(); for (i = 0; i <= 100; i++) { CkBinDataW_AppendEncoded(bd,L"000102030405060708090A0B0C0D0E0F",L"hex"); } // Load the signature bdSig = CkBinDataW_Create(); success = CkBinDataW_LoadFile(bdSig,L"rsaSignatures/test1.sig"); if (success == FALSE) { wprintf(L"Failed to load the RSA signature\n"); CkBinDataW_Dispose(bd); CkBinDataW_Dispose(bdSig); return; } // Get the public key to be used for signature verification. pubKey = CkPublicKeyW_Create(); success = CkPublicKeyW_LoadFromFile(pubKey,L"rsaKeys/chilkat-rsa-2048.pem"); if (success == FALSE) { wprintf(L"%s\n",CkPublicKeyW_lastErrorText(pubKey)); CkBinDataW_Dispose(bd); CkBinDataW_Dispose(bdSig); CkPublicKeyW_Dispose(pubKey); return; } rsa = CkRsaW_Create(); CkRsaW_ImportPublicKeyObj(rsa,pubKey); // Verify the hash of the data against the signature. // We pass in the original data. Internally, the hash is generated // and used to validate the signature. // Validating the RSA signature means two things: // (1) the original data is exactly what was signed, and // (2) it was signed by the owner of the RSA private key. success = CkRsaW_VerifyBd(rsa,bd,L"sha256",bdSig); if (success == FALSE) { wprintf(L"%s\n",CkRsaW_lastErrorText(rsa)); wprintf(L"Signature invalid.\n"); } else { wprintf(L"Signature valid.\n"); } CkBinDataW_Dispose(bd); CkBinDataW_Dispose(bdSig); CkPublicKeyW_Dispose(pubKey); CkRsaW_Dispose(rsa); } |
© 2000-2025 Chilkat Software, Inc. All Rights Reserved.