Sample code for 30+ languages & platforms
Node.js

Workaround for the deprecated EncryptString and DecryptString methods

Shows how to replace the deprecated EncryptString and DecryptString methods. (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.CryptAlgorithm = "aes";
    crypt.CipherMode = "cbc";
    crypt.KeyLength = 128;
    crypt.PaddingScheme = 0;
    crypt.SetEncodedKey("000102030405060708090A0B0C0D0E0F","hex");
    crypt.SetEncodedIV("000102030405060708090A0B0C0D0E0F","hex");

    success = false;

    crypt.Charset = "utf-8";
    var plainText = "text to be encrypted";

    //  ------------------------------------------------------------------------
    //  The EncryptString and DecryptString methods are deprecated:

    encryptedBytes = crypt.EncryptString(plainText);

    var decryptedStr = crypt.DecryptString(encryptedBytes);
    console.log("Decrypted: " + decryptedStr);

    //  ------------------------------------------------------------------------
    //  Replace the above CkByteData usage with the following code:
    //  (Chilkat is moving away from using CkByteData)

    var bd = new chilkat.BinData();
    bd.AppendString(plainText,"utf-8");

    //  in-place encrypt
    crypt.EncryptBd(bd);

    //  in-place decrypt
    crypt.DecryptBd(bd);
    decryptedStr = bd.GetString("utf-8");
    console.log("Decrypted: " + decryptedStr);

}

chilkatExample();