User Tools

Site Tools


encryptdecrypt

What are needed are the 2 components under the uses:

  • DCPrijndael for the cipher type
  • DCPsha256 for the hash type

The crypt.InitStr(passkey,TDCP_sha256) is needed everytime prior to encryption and decryption

unit Unit1;

{$mode objfpc}{$H+}

interface

uses
  Classes, SysUtils, Forms, Controls, Graphics, Dialogs, StdCtrls, DCPrijndael,
  DCPsha256;
type
  { TForm1 }
  TForm1 = class(TForm)
    Button1: TButton;
    Edit1: TEdit;
    Memo1: TMemo;
    procedure Button1Click(Sender: TObject);
  private
  public
  end;

var
  Form1: TForm1;

implementation

{$R *.frm}

procedure TForm1.Button1Click(Sender: TObject);
var origstr,encstr,decrstr:string;
    passkey : string;
    Crypt: TDCP_rijndael;
begin
   passkey := 'password';
   origstr := edit1.Text;
   crypt   := TDCP_rijndael.create(nil);
   crypt.InitStr(passkey,TDCP_sha256);
   encstr  := crypt.EncryptString(origstr);
   memo1.Lines.Clear;;
   memo1.lines.Add('orig: ' +origstr);
   memo1.lines.Add(' ');
   memo1.lines.Add('enc of orig: '+encstr);
   memo1.lines.Add(' ');
   crypt.InitStr(passkey,TDCP_sha256);
   decrstr := crypt.DecryptString(origstr);
   memo1.Lines.add('dec of orig: '+decrstr);
   crypt.InitStr(passkey,TDCP_sha256);
   decrstr := crypt.DecryptString(encstr);
   memo1.Lines.add('dec of encr: '+decrstr);
   edit1.SetFocus;
   freeandnil(crypt);
end;
end.
encryptdecrypt.txt · Last modified: by 127.0.0.1

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki