Recent

Author Topic: HMAC MD5 retunes raw binary data base64 encode  (Read 479 times)

project75

  • Newbie
  • Posts: 2
HMAC MD5 retunes raw binary data base64 encode
« on: August 08, 2024, 11:33:21 am »
Hello everyone, I have device that needs HMAC MD5 calculation to return the original binary data and then Base64 encode it. I can use Lazarus to generate the data of result A as shown in the figure[HMACMD5('1234567890', 'Hello world!');], and I can also Base64 encode result A[EncodeStringBase64(HMACMD5('1234567887654321', 'Hello world!'));]. Does anyone know how to generate the code of result B in the figure?

avk

  • Hero Member
  • *****
  • Posts: 756
Re: HMAC MD5 retunes raw binary data base64 encode
« Reply #1 on: August 08, 2024, 01:19:31 pm »
Maybe
Code: Pascal  [Select][+][-]
  1. ...
  2. function EncodeBase64(const aBuffer; aCount: Integer): string;
  3. var
  4.   ss: TStringStream;
  5. begin
  6.   Result := '';
  7.   if aCount < 1 then exit;
  8.   ss := TStringStream.Create;
  9.   try
  10.     with TBase64EncodingStream.Create(ss) do
  11.       try
  12.         Write(aBuffer, aCount);
  13.       finally
  14.         Free;
  15.       end;
  16.     Result := ss.DataString;
  17.   finally
  18.     ss.Free;
  19.   end;
  20. end;  
  21. ...
  22.   s := EncodeBase64(HMACMD5Digest('1234567887654321', 'Hello world!'), SizeOf(THMACMD5Digest))
  23. ...
  24.  

paweld

  • Hero Member
  • *****
  • Posts: 1219
Re: HMAC MD5 retunes raw binary data base64 encode
« Reply #2 on: August 08, 2024, 03:05:38 pm »
or:
Code: Pascal  [Select][+][-]
  1. uses
  2.   base64;
  3.  
  4. begin
  5.   s := EncodeStringBase64(HMACMD5Digest('1234567887654321', 'Hello world!'));
  6. end;
  7.  
Best regards / Pozdrawiam
paweld

project75

  • Newbie
  • Posts: 2
Re: HMAC MD5 retunes raw binary data base64 encode
« Reply #3 on: August 09, 2024, 06:50:42 am »
Thanks to @avk and @paweld for your help, my problem has been solved perfectly. Thank you again!

 

TinyPortal © 2005-2018