Chilkat HOME .NET Core C# Android™ AutoIt C C# C++ Chilkat2-Python CkPython Classic ASP DataFlex Delphi ActiveX Delphi DLL Go Java Lianja Mono C# Node.js Objective-C PHP ActiveX PHP Extension Perl PowerBuilder PowerShell PureBasic Ruby SQL Server Swift 2 Swift 3,4,5... Tcl Unicode C Unicode C++ VB.NET VBScript Visual Basic 6.0 Visual FoxPro Xojo Plugin
(Delphi DLL) RSA DecryptRSA decryption using a private key loaded from a PEM file. This example duplicates the following OpenSSL rsautl command: openssl rsautl -decrypt -inkey myPrivateKey.pem -in cipher.bin -out decrypted.bin
uses Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics, Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, FileAccess, PrivateKey, Rsa, CkByteData; ... procedure TForm1.Button1Click(Sender: TObject); var rsa: HCkRsa; privKey: HCkPrivateKey; success: Boolean; encFileData: HCkByteData; decFileData: HCkByteData; fac: HCkFileAccess; begin // This example assumes the Chilkat API to have been previously unlocked. // See Global Unlock Sample for sample code. rsa := CkRsa_Create(); privKey := CkPrivateKey_Create(); success := CkPrivateKey_LoadPemFile(privKey,'myPrivateKey.pem'); if (success <> True) then begin Memo1.Lines.Add(CkPrivateKey__lastErrorText(privKey)); Exit; end; success := CkRsa_ImportPrivateKeyObj(rsa,privKey); if (success <> True) then begin Memo1.Lines.Add(CkRsa__lastErrorText(rsa)); Exit; end; encFileData := CkByteData_Create(); decFileData := CkByteData_Create(); fac := CkFileAccess_Create(); success := CkFileAccess_ReadEntireFile(fac,'cipher.bin',encFileData); if (CkFileAccess_getLastMethodSuccess(fac) <> True) then begin Memo1.Lines.Add(CkFileAccess__lastErrorText(fac)); Exit; end; success := CkRsa_DecryptBytes(rsa,encFileData,True,decFileData); if (success <> True) then begin Memo1.Lines.Add(CkRsa__lastErrorText(rsa)); Exit; end; // Save the decrypted data to a file. success := CkFileAccess_WriteEntireFile(fac,'decrypted.bin',decFileData); if (success <> True) then begin Memo1.Lines.Add('Failed to save decrypted data.'); Exit; end; CkRsa_Dispose(rsa); CkPrivateKey_Dispose(privKey); CkByteData_Dispose(encFileData); CkByteData_Dispose(decFileData); CkFileAccess_Dispose(fac); end; |
© 2000-2024 Chilkat Software, Inc. All Rights Reserved.