Sample code for 30+ languages & platforms
JavaScript

Example: Crypt2.EncryptSb method

Demonstrates how to call the EncryptSb method.
Note
This example is intended for running within a Chilkat.Js embedded JavaScript engine. All Chilkat JavaScript examples require Chilkat v11.4.0 or greater.
JavaScript
var success = false;

var crypt = new CkCrypt2();

var bdEncrypted = new CkBinData();
var sbPlainText = new CkStringBuilder();

sbPlainText.Append("Text to be encrypted");

// ...
// Set the secret key ...
// Set properties such as CryptAlgorithm, CipherMode, PaddingScheme, KeyLength
// Set the IV if needed ...
// ...

crypt.Charset = "utf-8";

success = crypt.EncryptSb(sbPlainText,bdEncrypted);
if (success == false) {
    console.log(crypt.LastErrorText);
    return;
}