Sample code for 30+ languages & platforms
C

Workaround for the deprecated Crypt2.HashString method

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

Chilkat C Downloads

C
#include <C_CkCrypt2.h>
#include <C_CkByteData.h>

void ChilkatSample(void)
    {
    HCkCrypt2 crypt;
    const char *inputStr;
    HCkByteData outData;
    const char *hash_base64;

    crypt = CkCrypt2_Create();

    CkCrypt2_putCharset(crypt,"utf-8");

    CkCrypt2_putHashAlgorithm(crypt,"sha256");

    inputStr = "This is a test.";

    //  ------------------------------------------------------------------------
    //  The HashString method is deprecated:

    outData = CkByteData_Create();

    success = CkCrypt2_HashString(crypt,inputStr,outData);

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

    CkCrypt2_putEncodingMode(crypt,"base64");
    hash_base64 = CkCrypt2_hashStringENC(crypt,inputStr);

    printf("%s\n",hash_base64);


    CkCrypt2_Dispose(crypt);
    CkByteData_Dispose(outData);

    }