Xor-el / CryptoLib4Pascal

Crypto for Modern Object Pascal
MIT License
211 stars 65 forks source link

HMAC-SHA256 help needed #37

Closed ertankucukoglu closed 1 year ago

ertankucukoglu commented 1 year ago

Hello,

I am using Delphi 11.3 and trying to generate HMAC-SHA256. Samples codes only has single example to HMAC for PascalCoin. I came up with following code and it gives me compile error

uses
  ClpIDigest,
  ClpIMac,
  ClpDigestUtilities,
  ClpMacUtilities,
  ClpICipherParameters;

procedure TForm1.Button1Click(Sender: TObject);
var
  DigestMACInstance: IMac;
  Parameters: IChiperParameters; // [dcc32 Error] Unit1.pas(37): E2003 Undeclared identifier: 'IChiperParameters'
  LHMACBytes: TBytes;
begin
  DigestMACInstance := TMacUtilities.GetMac('HMAC-SHA256');
  // I believe Parameters to be assigned with my secret key and data to be hashed here
  DigestMACInstance.Init(Parameters);
  LHMACBytes := DigestMACInstance.DoFinal();
end;

I also saw TMacUtilities has direct reading of HMAC value which is easier to use in code but my problem is also valid for that use case as I need to pass parameters.

When I check ClpICipherParameters.pas it actually has empty interface defined in it.

I could not figure out my mistake. Any help is appreciated.

Thanks & Regards, Ertan

Xor-el commented 1 year ago

Hello Ertan, you can find samples of HMAC at https://github.com/Xor-el/CryptoLib4Pascal/blob/master/CryptoLib.Tests/src/Crypto/HMacTests.pas

Cheers.

On Wed, Aug 2, 2023 at 5:13 PM ertankucukoglu @.***> wrote:

Hello,

I am using Delphi 11.3 and trying to generate HMAC-SHA256. Samples codes only has single example to HMAC for PascalCoin. I came up with following code and it gives me compile error

uses ClpIDigest, ClpIMac, ClpDigestUtilities, ClpMacUtilities, ClpICipherParameters;

procedure TForm1.Button1Click(Sender: TObject); var DigestMACInstance: IMac; Parameters: IChiperParameters; // [dcc32 Error] Unit1.pas(37): E2003 Undeclared identifier: 'IChiperParameters' LHMACBytes: TBytes; begin DigestMACInstance := TMacUtilities.GetMac('HMAC-SHA256'); // I believe Parameters to be assigned with my secret key and data to be hashed here DigestMACInstance.Init(Parameters); LHMACBytes := DigestMACInstance.DoFinal(); end;

I also saw TMacUtilities has direct reading of HMAC value which is easier to use in code but my problem is also valid for that use case as I need to pass parameters.

When I check ClpICipherParameters.pas it actually has empty interface defined in it.

I could not figure out my mistake. Any help is appreciated.

Thanks & Regards, Ertan

— Reply to this email directly, view it on GitHub https://github.com/Xor-el/CryptoLib4Pascal/issues/37, or unsubscribe https://github.com/notifications/unsubscribe-auth/AC4P7ODDQ7LIYN7V7EUAEO3XTJ4BLANCNFSM6AAAAAA3BQI6LE . You are receiving this because you are subscribed to this thread.Message ID: @.***>

ertankucukoglu commented 1 year ago

I knew I missed something. That did the job.

Thank you.

Xor-el commented 1 year ago

You're welcome!

On Wed, 2 Aug 2023, 19:01 ertankucukoglu, @.***> wrote:

I knew I missed something. That did the job.

Thank you.

— Reply to this email directly, view it on GitHub https://github.com/Xor-el/CryptoLib4Pascal/issues/37#issuecomment-1662704581, or unsubscribe https://github.com/notifications/unsubscribe-auth/AC4P7OHOP4CRTK4XMKJJ2GTXTKIXPANCNFSM6AAAAAA3BQI6LE . You are receiving this because you commented.Message ID: @.***>