lib/core/cipher.js
function encryptJson(password, json) {
    return Q.all([
        randomBytes(pbkdf2SaltLen),
        randomBytes(cipherIvLen)
    ]).spread(function (salt, iv) {
        return pbkdf2(password, salt, pbkdf2Iterations, pbkdf2KeyLen, pbkdf2Digest).then(function (key) {
            var cipher = crypto.createCipheriv(cipherAlgorithm, key, iv);
            var value = cipher.update(JSON.stringify(json), 'utf8', 'base64');
            value += cipher.final('base64');
            var data = {
                salt: salt.toString('base64'),
                iv: iv.toString('base64'),
                value: value
            };
            var tag = cipher.getAuthTag();
            if (tag) {
                data.tag = tag.toString('base64');
            }
            return data;
        });
    });
}
function encryptJson(password, json) {
    return Q.all([
        randomBytes(pbkdf2SaltLen),
        randomBytes(cipherIvLen)
    ]).spread(function (salt, iv) {
        return pbkdf2(password, salt, pbkdf2Iterations, pbkdf2KeyLen, pbkdf2Digest).then(function (key) {
            var cipher = crypto.createCipheriv(cipherAlgorithm, key, iv);
            var value = cipher.update(JSON.stringify(json), 'utf8', 'base64');
            value += cipher.final('base64');
            var data = {
                salt: salt.toString('base64'),
                iv: iv.toString('base64'),
                value: value
            };
            var tag = cipher.getAuthTag();
            if (tag) {
                data.tag = tag.toString('base64');
            }
            return data;
        });
    });
}
function encryptJson ( password , json ) { return Q . all ( [ randomBytes ( pbkdf2SaltLen ) , randomBytes ( cipherIvLen ) ] ) . spread ( function ( salt , iv ) { return pbkdf2 ( password , salt , pbkdf2Iterations , pbkdf2KeyLen , pbkdf2Digest ) . then ( function ( key ) { var cipher = crypto . createCipheriv ( cipherAlgorithm , key , iv ) ; var value = cipher . update ( JSON . stringify ( json ) , 'utf8' , 'base64' ) ; value += cipher . final ( 'base64' ) ; var data = { salt : salt . toString ( 'base64' ) , iv : iv . toString ( 'base64' ) , value : value } ; var tag = cipher . getAuthTag ( ) ; if ( tag ) { data . tag = tag . toString ( 'base64' ) ; } return data ; } ) ; } ) ; }
encrypts a JSON object using a user-provided password.

This method is suitable for human-entered passwords and not appropriate for machine generated
passwords. Make sure to read regarding pbkdf2.

@param password of a human.
@param json to encode.
@return encoded json data.

@internal Not part of public API, exported for library use only.
encrypts a JSON object using a user - provided password .