![]() |
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
(Lianja) RSA Hash Binary Data and Sign (and Verify)Demonstrates how to sign the hash of binary data. Also demonstrates how to verify the RSA signature. Note: This example requires Chilkat v11.0.0 or greater.
llSuccess = .F. // This example requires the Chilkat API to have been previously unlocked. // See Global Unlock Sample for sample code. // Load an RSA private key for signing. loPrivKey = createobject("CkPrivateKey") llSuccess = loPrivKey.LoadEncryptedPemFile("qa_data/pem/rsa_passwd.pem","passwd") if (llSuccess = .F.) then ? loPrivKey.LastErrorText release loPrivKey return endif loRsa = createobject("CkRsa") loRsa.UsePrivateKey(loPrivKey) // We have some binary data (in hex) to sign lcOriginalData = "0102030405060708090A" loBdData = createobject("CkBinData") loBdData.AppendEncoded(lcOriginalData,"hex") // Hash (SHA-256) and sign the hash: loBdSignature = createobject("CkBinData") llSuccess = loRsa.SignBd(loBdData,"sha256",loBdSignature) if (llSuccess = .F.) then ? loRsa.LastErrorText release loPrivKey release loRsa release loBdData release loBdSignature return endif // Show the RSA signature in base64 ? loBdSignature.GetEncoded("base64") // ------------------------------------------ // Get the public key from the private key loPubKey = createobject("CkPublicKey") loPrivKey.ToPublicKey(loPubKey) // Verify the signature.. loRsa2 = createobject("CkRsa") loRsa2.UsePublicKey(loPubKey) llBVerified = loRsa2.VerifyBd(loBdData,"sha256",loBdSignature) ? "signature verified: " + str(llBVerified) release loPrivKey release loRsa release loBdData release loBdSignature release loPubKey release loRsa2 |
© 2000-2025 Chilkat Software, Inc. All Rights Reserved.