Encrypt and Decrypt files on the disk.

Download source code

This sample cryptographically encrypts / decrypts files with digital x509 certificate.

procedure TForm1.btnEncryptClick(Sender: TObject);
var
  dlg: TGetCertDialog;
begin
  dlg := TGetCertDialog.Create(nil);
  try
    dlg.Caption := 'Get encryption certificate';
    if (dlg.ShowModal() = mrOK) then
    begin
      clEncryptor1.EncryptStore := dlg.edtStore.Text;
      clEncryptor1.EncryptCertificate := dlg.edtEmail.Text;
    end;
  finally
    dlg.Free();
  end;

  clEncryptor1.Encrypt(edtSource.Text, edtDestination.Text);

  ShowMessage(Format('The file %s was encrypted and stored to %s', [edtSource.Text, edtDestination.Text]));
end;
 
procedure TForm1.btnDecryptClick(Sender: TObject);
var
  dlg: TGetCertDialog;
begin
  dlg := TGetCertDialog.Create(nil);
  try
    dlg.Caption := 'Get encryption certificate';
    if (dlg.ShowModal() = mrOK) then
    begin
      clEncryptor1.EncryptStore := dlg.edtStore.Text;
      clEncryptor1.EncryptCertificate := dlg.edtEmail.Text;
    end;
  finally
    dlg.Free();
  end;

  clEncryptor1.Decrypt(edtSource.Text, edtDestination.Text);

  ShowMessage(Format('The file %s was decrypted and stored to %s', [edtSource.Text, edtDestination.Text]));
end;
 

Add Feedback