![]() |
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
(DataFlex) RSA Sign Using Private Key from .pfx/.p12 to Base64 SignatureSee more RSA ExamplesDemonstrates how to RSA sign something using a private key loaded from a .pfx/.p12. The RSA signature is returned in Base64 encoded format.
Use ChilkatAx-win32.pkg Procedure Test Handle hoRsa Handle hoPfx Boolean iSuccess Variant vPrivKey Handle hoPrivKey String sStrData String sBase64Sig String sTemp1 Boolean bTemp1 // This example assumes the Chilkat API to have been previously unlocked. // See Global Unlock Sample for sample code. Get Create (RefClass(cComChilkatRsa)) To hoRsa If (Not(IsComObjectCreated(hoRsa))) Begin Send CreateComObject of hoRsa End // Load the .pfx/.p12 Get Create (RefClass(cComChilkatPfx)) To hoPfx If (Not(IsComObjectCreated(hoPfx))) Begin Send CreateComObject of hoPfx End Get ComLoadPfxFile Of hoPfx "qa_data/pfx/myKey.p12" "myPassword" To iSuccess If (iSuccess <> True) Begin Get ComLastErrorText Of hoPfx To sTemp1 Showln sTemp1 Procedure_Return End // Get the default private key. Get ComGetPrivateKey Of hoPfx 0 To vPrivKey If (IsComObject(vPrivKey)) Begin Get Create (RefClass(cComChilkatPrivateKey)) To hoPrivKey Set pvComObject Of hoPrivKey To vPrivKey End Get ComLastMethodSuccess Of hoPfx To bTemp1 If (bTemp1 <> True) Begin Get ComLastErrorText Of hoPfx To sTemp1 Showln sTemp1 Procedure_Return End // Import the private key into the RSA component: Get ComImportPrivateKeyObj Of hoRsa vPrivKey To iSuccess If (iSuccess <> True) Begin Get ComLastErrorText Of hoRsa To sTemp1 Showln sTemp1 Send Destroy of hoPrivKey Procedure_Return End Send Destroy of hoPrivKey // Get the signature in base64 Set ComEncodingMode Of hoRsa To "base64" Move "This is the string to be signed." To sStrData // Sign the string using the sha256 hash algorithm. // Other valid choices are "sha384", "sha512", "sha-1", "md2" and "md5". Get ComSignStringENC Of hoRsa sStrData "sha256" To sBase64Sig Showln sBase64Sig Showln "Success!" End_Procedure |
© 2000-2025 Chilkat Software, Inc. All Rights Reserved.