![]() |
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
(C) Duplicating OpenSSL rsautl (creating RSA signatures)Demonstrates how to duplicate OpenSSL rsautil RSA signatures. The Chilkat RSA component's methods for creating RSA signatures (SignBytes, SignBytesENC, SignString, and SignStringENC) are very different from OpenSSL's rsautl command. First, we'll explain what Chilkat's signing methods do, and then what OpenSSL's rsautl does. New signing methods have been added to Chilkat RSA to duplicate OpenSSL rsautl: OpenSslSignBytes, OpenSslSignBytesENC, OpenSslSignString, and OpenSslSignStringENC.
Here's what Chilkat's RSA Sign* methods do:
OpenSSL rsautl is very different. Here's what it does:
Note: This example requires Chilkat v11.0.0 or greater.
#include <C_CkPrivateKey.h> #include <C_CkRsa.h> #include <C_CkBinData.h> #include <C_CkPublicKey.h> void ChilkatSample(void) { BOOL success; HCkPrivateKey privKey; HCkRsa rsa; const char *strData; HCkBinData bd; const char *hexSig; HCkPublicKey pubKey; HCkRsa rsa2; HCkBinData bd2; const char *originalData; success = FALSE; // This example assumes the Chilkat API to have been previously unlocked. // See Global Unlock Sample for sample code. privKey = CkPrivateKey_Create(); // Load the private key from an RSA PEM file: success = CkPrivateKey_LoadPemFile(privKey,"private.pem"); if (success == FALSE) { printf("%s\n",CkPrivateKey_lastErrorText(privKey)); CkPrivateKey_Dispose(privKey); return; } rsa = CkRsa_Create(); success = CkRsa_UsePrivateKey(rsa,privKey); if (success == FALSE) { printf("%s\n",CkRsa_lastErrorText(rsa)); CkPrivateKey_Dispose(privKey); CkRsa_Dispose(rsa); return; } strData = "secret"; bd = CkBinData_Create(); CkBinData_AppendString(bd,strData,"utf-8"); success = CkRsa_SignRawBd(rsa,bd); hexSig = CkBinData_getEncoded(bd,"hex"); printf("%s\n",hexSig); // Recover the data using the corresponding public key: pubKey = CkPublicKey_Create(); // Load the public key from a PEM file: success = CkPublicKey_LoadFromFile(pubKey,"public.pem"); if (success == FALSE) { printf("%s\n",CkPublicKey_lastErrorText(pubKey)); CkPrivateKey_Dispose(privKey); CkRsa_Dispose(rsa); CkBinData_Dispose(bd); CkPublicKey_Dispose(pubKey); return; } rsa2 = CkRsa_Create(); success = CkRsa_UsePublicKey(rsa2,pubKey); if (success == FALSE) { printf("%s\n",CkRsa_lastErrorText(rsa2)); CkPrivateKey_Dispose(privKey); CkRsa_Dispose(rsa); CkBinData_Dispose(bd); CkPublicKey_Dispose(pubKey); CkRsa_Dispose(rsa2); return; } bd2 = CkBinData_Create(); CkBinData_AppendEncoded(bd2,hexSig,"hex"); // Recover the original data. success = CkRsa_VerifyRawBd(rsa2,bd2); if (success == FALSE) { printf("%s\n",CkRsa_lastErrorText(rsa2)); CkPrivateKey_Dispose(privKey); CkRsa_Dispose(rsa); CkBinData_Dispose(bd); CkPublicKey_Dispose(pubKey); CkRsa_Dispose(rsa2); CkBinData_Dispose(bd2); return; } originalData = CkBinData_getString(bd2,"utf-8"); printf("%s\n",originalData); CkPrivateKey_Dispose(privKey); CkRsa_Dispose(rsa); CkBinData_Dispose(bd); CkPublicKey_Dispose(pubKey); CkRsa_Dispose(rsa2); CkBinData_Dispose(bd2); } |
© 2000-2025 Chilkat Software, Inc. All Rights Reserved.