util/cipherUtil.js
function pwCipher(string) {

        if(string) {

            if ( typeof pw !== 'string' || pw.length < 8 ) {
                throw new Error('Please set a password with 8 or ' +
                    'more chars on process.env.CIPHER_UTIL_PW!');
            }

            if ( typeof algo !== 'string' || algo.length < 1 ) {
                throw new Error('Please choose an algorithm' +
                    ' on process.env.CIPHER_UTIL_ALGO!');
            }

            var ciphered = crypto.createCipher(algo, pw),

            /*
             * Array
             */
            encrypted = [ciphered.update(string)];

            encrypted.push(ciphered.final());

            return Buffer.concat(encrypted).toString(pwEnc);

        }

        return null;

    }
function pwCipher(string) {

        if(string) {

            if ( typeof pw !== 'string' || pw.length < 8 ) {
                throw new Error('Please set a password with 8 or ' +
                    'more chars on process.env.CIPHER_UTIL_PW!');
            }

            if ( typeof algo !== 'string' || algo.length < 1 ) {
                throw new Error('Please choose an algorithm' +
                    ' on process.env.CIPHER_UTIL_ALGO!');
            }

            var ciphered = crypto.createCipher(algo, pw),

            /*
             * Array
             */
            encrypted = [ciphered.update(string)];

            encrypted.push(ciphered.final());

            return Buffer.concat(encrypted).toString(pwEnc);

        }

        return null;

    }
function pwCipher ( string ) { if ( string ) { if ( typeof pw !== 'string' || pw . length < 8 ) { throw new Error ( 'Please set a password with 8 or ' + 'more chars on process.env.CIPHER_UTIL_PW!' ) ; } if ( typeof algo !== 'string' || algo . length < 1 ) { throw new Error ( 'Please choose an algorithm' + ' on process.env.CIPHER_UTIL_ALGO!' ) ; } var ciphered = crypto . createCipher ( algo , pw ) , /*
             * Array
             */ encrypted = [ ciphered . update ( string ) ] ; encrypted . push ( ciphered . final ( ) ) ; return Buffer . concat ( encrypted ) . toString ( pwEnc ) ; } return null ; }
Encrypt string with password and specified algorithm.

@param string {String} String to encrypt.
@return {String | Null}
Encrypt string with password and specified algorithm .