Sample code for 30+ languages & platforms
Node.js

Workaround for the deprecated Crypt2.MacString method

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

Chilkat Node.js Downloads

Node.js
NODEJS_PRELUDE

function chilkatExample() {

    var success = false;

    var crypt = new chilkat.Crypt2();

    crypt.Charset = "utf-8";

    //  Do HMAC using SHA-256.
    crypt.MacAlgorithm = "hmac";
    crypt.HashAlgorithm = "sha256";

    var keyHex = "000102030405060708090A0B0C0D0E0F";
    success = crypt.SetMacKeyEncoded(keyHex,"hex");

    var inputStr = "This is a test.";

    //  ------------------------------------------------------------------------
    //  The MacString method is deprecated:

    outData = crypt.MacString(inputStr);

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

    crypt.EncodingMode = "base64";
    var mac_base64 = crypt.MacStringENC(inputStr);

    console.log(mac_base64);

}

chilkatExample();