hsha1.pp 801 B

12345678910111213141516171819202122232425262728293031323334
  1. // See some samples in: http://en.wikipedia.org/wiki/Hash-based_message_authentication_code
  2. program hsha1;
  3. {$mode objfpc}
  4. {$H+}
  5. uses
  6. {$ifdef unix}
  7. cwstring,
  8. {$endif}
  9. HMAC;
  10. var
  11. S : String;
  12. begin
  13. // for HMAC_SHA1("", "") = 0xfbdb1d1b18aa6c08324b7d64b71fb76370690e1d
  14. S:=HMACSHA1Print(HMACSHA1Digest('', ''));
  15. WriteLn('Example 1: ', S);
  16. if (S<>'fbdb1d1b18aa6c08324b7d64b71fb76370690e1d') then
  17. begin
  18. Writeln('Failed 1');
  19. Halt(1);
  20. end;
  21. // for HMAC_SHA1("key", "The quick brown fox jumps over the lazy dog") = 0xde7c9b85b8b78aa6bc8a7a36f70a90701c9db4d9
  22. S:=HMACSHA1('key', 'The quick brown fox jumps over the lazy dog');
  23. WriteLn('Example 2: ', S);
  24. if (S<>'de7c9b85b8b78aa6bc8a7a36f70a90701c9db4d9') then
  25. begin
  26. Writeln('Failed 2');
  27. Halt(2);
  28. end;
  29. end.