(C++) Workaround for the deprecated Crypt2.MacString method
Shows how to replace the deprecated MacString method. (Chilkat is moving away from the use of CkByteData.) Note: This example requires Chilkat v11.0.0 or greater.
#include <CkCrypt2.h>
#include <CkByteData.h>
void ChilkatSample(void)
{
CkCrypt2 crypt;
crypt.put_Charset("utf-8");
// Do HMAC using SHA-256.
crypt.put_MacAlgorithm("hmac");
crypt.put_HashAlgorithm("sha256");
const char *keyHex = "000102030405060708090A0B0C0D0E0F";
bool success = crypt.SetMacKeyEncoded(keyHex,"hex");
const char *inputStr = "This is a test.";
// ------------------------------------------------------------------------
// The MacString method is deprecated:
CkByteData outData;
success = crypt.MacString(inputStr,outData);
// ------------------------------------------------------------------------
// Workaround.
// (Chilkat is moving away from using CkByteData)
crypt.put_EncodingMode("base64");
const char *mac_base64 = crypt.macStringENC(inputStr);
std::cout << mac_base64 << "\r\n";
}
|