Loque

lazarus sha256 string hash

Sep 27th, 2021 (edited)
981
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // installa DCPCrypt
  2. // il form contiene due edit ed un button
  3. unit Unit1;
  4.  
  5. {$mode objfpc}{$H+}
  6.  
  7. interface
  8.  
  9. uses
  10.   Classes, SysUtils, Forms, Controls, Graphics, DCPsha256, StdCtrls;
  11.  
  12. type
  13.  
  14.   { TForm1 }
  15.  
  16.   TForm1 = class(TForm)
  17.     Button1: TButton;
  18.     DCP_sha256_1: TDCP_sha256;
  19.     Edit1: TEdit;
  20.     Edit2: TEdit;
  21.     procedure Button1Click(Sender: TObject);
  22.   private
  23.     { private declarations }
  24.   public
  25.  
  26.     { public declarations }
  27.   end;
  28.  
  29. var
  30.   Form1: TForm1;
  31.  
  32. implementation
  33.  
  34. {$R *.lfm}
  35.  
  36. { TForm1 }
  37.  
  38. function getsha256(S: String): String;
  39. var
  40.     Hash: TDCP_sha256;
  41.     Digest: array[0..31] of byte;  // sha256 produces a 256bit digest (32bytes)
  42.     Source: string;
  43.     i: integer;
  44.     str1: string;
  45.   begin
  46.     Source:= S;  // here your string for get sha256
  47.  
  48.     if Source <> '' then
  49.     begin
  50.       Hash:= TDCP_sha256.Create(nil);  // create the hash
  51.       Hash.Init;                        // initialize it
  52.       Hash.UpdateStr(Source);
  53.       Hash.Final(Digest);               // produce the digest
  54.       str1:= '';
  55.       for i:= 0 to 31 do
  56.         str1:= str1 + IntToHex(Digest[i],2);
  57.       //form1.Edit2.Text:= s;                   // display the digest in lower case
  58.       Result:=UpperCase(str1);         // display the digest in capital letter
  59.     end;
  60.   end;
  61.  
  62. procedure TForm1.Button1Click(Sender: TObject);
  63.   begin
  64.     Edit2.Text:=getsha256(Edit1.Text);  // show the sha256 of string in edit1
  65. end;
  66. end.
RAW Paste Data