Sample code for 30+ languages & platforms
Delphi DLL Requires Chilkat v11.0.0+

Workaround for the deprecated Crypt2.MacBytesENC method

Shows how to replace the deprecated MacBytesENC method. (Chilkat is moving away from the use of CkByteData.)

Chilkat Delphi DLL Downloads

Delphi DLL
var
success: Boolean;
crypt: HCkCrypt2;
keyHex: PWideChar;
path: PWideChar;
inData: HCkByteData;
hmac_hex: PWideChar;
bdIn: HCkBinData;

begin
success := False;

crypt := CkCrypt2_Create();

//  Do HMAC using SHA-256.
CkCrypt2_putMacAlgorithm(crypt,'hmac');
CkCrypt2_putHashAlgorithm(crypt,'sha256');

keyHex := '000102030405060708090A0B0C0D0E0F';
success := CkCrypt2_SetMacKeyEncoded(crypt,keyHex,'hex');

//  Return the HMAC using the lowercase hex encoding.
CkCrypt2_putEncodingMode(crypt,'hex_lower');

path := 'c:/someDir/example.dat';

//  ------------------------------------------------------------------------
//  The MacBytesENC method is deprecated:

inData := CkByteData_Create();
CkByteData_loadFile(inData,path);

hmac_hex := CkCrypt2__macBytesENC(crypt,inData);
Memo1.Lines.Add(hmac_hex);

//  ------------------------------------------------------------------------
//  Workaround.
//  (Chilkat is moving away from using CkByteData)

bdIn := CkBinData_Create();
CkBinData_LoadFile(bdIn,path);

hmac_hex := CkCrypt2__macBdENC(crypt,bdIn);
Memo1.Lines.Add(hmac_hex);

CkCrypt2_Dispose(crypt);
CkByteData_Dispose(inData);
CkBinData_Dispose(bdIn);