![]() |
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
(PureBasic) 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.
IncludeFile "CkBinData.pb" IncludeFile "CkPublicKey.pb" IncludeFile "CkPrivateKey.pb" IncludeFile "CkRsa.pb" Procedure ChilkatExample() success.i = 0 ; This example assumes the Chilkat API to have been previously unlocked. ; See Global Unlock Sample for sample code. privKey.i = CkPrivateKey::ckCreate() If privKey.i = 0 Debug "Failed to create object." ProcedureReturn EndIf ; Load the private key from an RSA PEM file: success = CkPrivateKey::ckLoadPemFile(privKey,"private.pem") If success = 0 Debug CkPrivateKey::ckLastErrorText(privKey) CkPrivateKey::ckDispose(privKey) ProcedureReturn EndIf rsa.i = CkRsa::ckCreate() If rsa.i = 0 Debug "Failed to create object." ProcedureReturn EndIf success = CkRsa::ckUsePrivateKey(rsa,privKey) If success = 0 Debug CkRsa::ckLastErrorText(rsa) CkPrivateKey::ckDispose(privKey) CkRsa::ckDispose(rsa) ProcedureReturn EndIf strData.s = "secret" bd.i = CkBinData::ckCreate() If bd.i = 0 Debug "Failed to create object." ProcedureReturn EndIf CkBinData::ckAppendString(bd,strData,"utf-8") success = CkRsa::ckSignRawBd(rsa,bd) hexSig.s = CkBinData::ckGetEncoded(bd,"hex") Debug hexSig ; Recover the data using the corresponding public key: pubKey.i = CkPublicKey::ckCreate() If pubKey.i = 0 Debug "Failed to create object." ProcedureReturn EndIf ; Load the public key from a PEM file: success = CkPublicKey::ckLoadFromFile(pubKey,"public.pem") If success = 0 Debug CkPublicKey::ckLastErrorText(pubKey) CkPrivateKey::ckDispose(privKey) CkRsa::ckDispose(rsa) CkBinData::ckDispose(bd) CkPublicKey::ckDispose(pubKey) ProcedureReturn EndIf rsa2.i = CkRsa::ckCreate() If rsa2.i = 0 Debug "Failed to create object." ProcedureReturn EndIf success = CkRsa::ckUsePublicKey(rsa2,pubKey) If success = 0 Debug CkRsa::ckLastErrorText(rsa2) CkPrivateKey::ckDispose(privKey) CkRsa::ckDispose(rsa) CkBinData::ckDispose(bd) CkPublicKey::ckDispose(pubKey) CkRsa::ckDispose(rsa2) ProcedureReturn EndIf bd2.i = CkBinData::ckCreate() If bd2.i = 0 Debug "Failed to create object." ProcedureReturn EndIf CkBinData::ckAppendEncoded(bd2,hexSig,"hex") ; Recover the original data. success = CkRsa::ckVerifyRawBd(rsa2,bd2) If success = 0 Debug CkRsa::ckLastErrorText(rsa2) CkPrivateKey::ckDispose(privKey) CkRsa::ckDispose(rsa) CkBinData::ckDispose(bd) CkPublicKey::ckDispose(pubKey) CkRsa::ckDispose(rsa2) CkBinData::ckDispose(bd2) ProcedureReturn EndIf originalData.s = CkBinData::ckGetString(bd2,"utf-8") Debug originalData CkPrivateKey::ckDispose(privKey) CkRsa::ckDispose(rsa) CkBinData::ckDispose(bd) CkPublicKey::ckDispose(pubKey) CkRsa::ckDispose(rsa2) CkBinData::ckDispose(bd2) ProcedureReturn EndProcedure |
© 2000-2025 Chilkat Software, Inc. All Rights Reserved.