Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // installa DCPCrypt
- // il form contiene due edit ed un button
- unit Unit1;
- {$mode objfpc}{$H+}
- interface
- uses
- Classes, SysUtils, Forms, Controls, Graphics, DCPsha256, StdCtrls;
- type
- { TForm1 }
- TForm1 = class(TForm)
- Button1: TButton;
- DCP_sha256_1: TDCP_sha256;
- Edit1: TEdit;
- Edit2: TEdit;
- procedure Button1Click(Sender: TObject);
- private
- { private declarations }
- public
- { public declarations }
- end;
- var
- Form1: TForm1;
- implementation
- {$R *.lfm}
- { TForm1 }
- function getsha256(S: String): String;
- var
- Hash: TDCP_sha256;
- Digest: array[0..31] of byte; // sha256 produces a 256bit digest (32bytes)
- Source: string;
- i: integer;
- str1: string;
- begin
- Source:= S; // here your string for get sha256
- if Source <> '' then
- begin
- Hash:= TDCP_sha256.Create(nil); // create the hash
- Hash.Init; // initialize it
- Hash.UpdateStr(Source);
- Hash.Final(Digest); // produce the digest
- str1:= '';
- for i:= 0 to 31 do
- str1:= str1 + IntToHex(Digest[i],2);
- //form1.Edit2.Text:= s; // display the digest in lower case
- Result:=UpperCase(str1); // display the digest in capital letter
- end;
- end;
- procedure TForm1.Button1Click(Sender: TObject);
- begin
- Edit2.Text:=getsha256(Edit1.Text); // show the sha256 of string in edit1
- end;
- end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement