demosha256.pp 997 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. {
  2. This file is part of the Free Component Library.
  3. Copyright (c) 2023 by the Free Pascal team.
  4. Demonstrate SHA 256 routines.
  5. See the file COPYING.FPC, included in this distribution,
  6. for details about the copyright.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  10. }
  11. program demosha256;
  12. {$mode objfpc}
  13. {$h+}
  14. uses SysUtils, fpsha256, fphashutils;
  15. procedure SHA256Test;
  16. var
  17. aSource,Digest : AnsiString;
  18. S : TBytes;
  19. begin
  20. aSource:='abc';
  21. S:=TEncoding.UTF8.GetAnsiBytes(aSource);
  22. SHA256Hexa(S, Digest);
  23. if (Digest<> 'BA7816BF8F01CFEA414140DE5DAE2223B00361A396177A9CB410FF61F20015AD') then
  24. raise Exception.Create('ERR_SHA256');
  25. SetLength(S,0);
  26. SHA256Hexa(S, Digest);
  27. if (Digest<> 'E3B0C44298FC1C149AFBF4C8996FB92427AE41E4649B934CA495991B7852B855') then
  28. raise Exception.Create('ERR_SHA256');
  29. end;
  30. begin
  31. SHA256Test
  32. end.