Bookstore

Recent

Author Topic: HashLib4Pascal  (Read 22672 times)

Xor-el

  • Sr. Member
  • ****
  • Posts: 408
Re: HashLib4Pascal
« Reply #60 on: January 20, 2020, 08:23:55 am »
BTW I need a
Quote
"{SHA}" + Base64-encoded SHA-1 digest of the password
only (-nbs).
HashLib4Pascal has support for SHA-1 including a host of other algorithms.
for Base64, you can use https://github.com/Xor-el/SimpleBaseLib4Pascal

trevor

  • New Member
  • *
  • Posts: 10
Re: HashLib4Pascal
« Reply #61 on: January 20, 2020, 10:07:32 am »
BTW I need a
Quote
"{SHA}" + Base64-encoded SHA-1 digest of the password
only (-nbs).
HashLib4Pascal has support for SHA-1 including a host of other algorithms.
for Base64, you can use https://github.com/Xor-el/SimpleBaseLib4Pascal

Thanks! I'm trying to figure out but so far unsuccessfully:

Code: Pascal  [Select]
  1. var
  2.   shah: IHash;
  3. begin
  4.   shah := TSHA1.Create();
  5.   Memo1.Text := shah.ComputeString(Edit1.Text, TEncoding.UTF8);
  6. end;

Now I need to wrap 'shah' into base64 right? Something like 'TBase64(shah.ComputeString(Edit1.Text, TEncoding.UTF8))'?

Code: Pascal  [Select]
  1.     class property Default: IBase64 read GetDefault;
  2.     class property DefaultNoPadding: IBase64 read GetDefaultNoPadding;
  3.     class property UrlEncoding: IBase64 read GetUrlEncoding;
  4.     class property XmlEncoding: IBase64 read GetXmlEncoding;
  5.     class property RegExEncoding: IBase64 read GetRegExEncoding;
  6.     class property FileEncoding: IBase64 read GetFileEncoding;

So what should I use?

Xor-el

  • Sr. Member
  • ****
  • Posts: 408
Re: HashLib4Pascal
« Reply #62 on: January 20, 2020, 10:28:38 am »
@trevor, below is a Demo that computes the output using the SHA-1 algorithm and compares the result to the one found at https://httpd.apache.org/docs/2.4/misc/password_encryptions.html.
You will need the HashLib4Pascal and SimpleBaseLib4Pascal packages as they are dependencies.

Code: Pascal  [Select]
  1. program PassDemo;
  2.  
  3. uses
  4.   SysUtils,
  5.   SbpBase64,
  6.   HlpHashFactory;
  7.  
  8. var
  9.   Password, Result: string;
  10. begin
  11.   Password := 'myPassword';
  12.   Result := '{SHA}' + TBase64.Default.Encode(
  13.     THashFactory.TCrypto.CreateSHA1().ComputeString(
  14.     Password, TEncoding.UTF8).GetBytes());
  15.   WriteLn(Result);
  16.   Assert(Result = '{SHA}VBPuJHI7uixaa6LQGWx4s+5GKNE=');
  17.   ReadLn;
  18. end.
  19.  

trevor

  • New Member
  • *
  • Posts: 10
Re: HashLib4Pascal
« Reply #63 on: January 20, 2020, 10:42:52 am »
@trevor, below is a Demo that computes the output using the SHA-1 algorithm and compares the result to the one found at https://httpd.apache.org/docs/2.4/misc/password_encryptions.html.
You will need the HashLib4Pascal and SimpleBaseLib4Pascal packages as they are dependencies.

Code: Pascal  [Select]
  1. program PassDemo;
  2.  
  3. uses
  4.   SysUtils,
  5.   SbpBase64,
  6.   HlpHashFactory;
  7.  
  8. var
  9.   Password, Result: string;
  10. begin
  11.   Password := 'myPassword';
  12.   Result := '{SHA}' + TBase64.Default.Encode(
  13.     THashFactory.TCrypto.CreateSHA1().ComputeString(
  14.     Password, TEncoding.UTF8).GetBytes());
  15.   WriteLn(Result);
  16.   Assert(Result = '{SHA}VBPuJHI7uixaa6LQGWx4s+5GKNE=');
  17.   ReadLn;
  18. end.
  19.  

Thanks a lot! You're the best! Exactly what I need!  ;D

Xor-el

  • Sr. Member
  • ****
  • Posts: 408
Re: HashLib4Pascal
« Reply #64 on: February 18, 2020, 09:11:58 am »
updated to version 4.1

- changelog from 4.0 to 4.1

* add Blake3 and Blake3XOF support
* performance improvements especially XOF Related.

** Now updated in OPM