![]() |
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
(Delphi DLL) RSA DecryptSee more RSA ExamplesRSA 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 Note: This example requires Chilkat v11.0.0 or greater.
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 success: Boolean; rsa: HCkRsa; privKey: HCkPrivateKey; encFileData: HCkByteData; decFileData: HCkByteData; fac: HCkFileAccess; begin success := False; // 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 = False) then begin Memo1.Lines.Add(CkPrivateKey__lastErrorText(privKey)); Exit; end; success := CkRsa_UsePrivateKey(rsa,privKey); if (success = False) 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) = False) then begin Memo1.Lines.Add(CkFileAccess__lastErrorText(fac)); Exit; end; success := CkRsa_DecryptBytes(rsa,encFileData,True,decFileData); if (success = False) 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-2025 Chilkat Software, Inc. All Rights Reserved.