How to use the createCipher function from crypto

Find comprehensive JavaScript crypto.createCipher code examples handpicked from public code repositorys.

232
233
234
235
236
237
238
239
240

* Encryption example using Cipher

```js
const crypto = require('crypto');  
const cipher = crypto.createCipher('aes192', 'a password');  

const encrypted = cipher.update('Hello Node.js', 'utf8', 'hex');  
encrypted += cipher.final('hex');  
fork icon932
star icon0
watch icon52

+ 3 other calls in file

159
160
161
162
163
164
165
166
167
168
  }
}

if (test.password) {
  if (common.hasFipsCrypto) {
    assert.throws(() => { crypto.createCipher(test.algo, test.password); },
                  errMessages.FIPS);
  } else {
    const encrypt = crypto.createCipher(test.algo, test.password, options);
    if (test.aad)
fork icon42
star icon19
watch icon0

+ 11 other calls in file

48
49
50
51
52
53
54
55
56
57
 * @param {string} text - The input text.
 * @param {string} seed - A seed to use for the symmetric encryption.
 * @returns {string} The encrypted representation of the given text.
 */
module.exports.encryptTextSync = function (text, seed) {
    var cipher = crypto.createCipher('aes-128-cbc', seed);
    var crypted = cipher.update(text, 'utf8', 'hex');
    crypted += cipher.final('hex');
    return crypted;
};
fork icon3
star icon5
watch icon3

189
190
191
192
193
194
195
196
197
198
  var cipher = crypto.createCipheriv('aes-256-cbc', key, iv);
  cipher.setAutoPadding(true);
  return cipher.update(data, 'utf8', 'base64') + cipher.final('base64');
};
exports.encryptOld = function (data, key) {
  var cipher = crypto.createCipher('aes-256-cbc', key);
  cipher.setAutoPadding(true);
  return cipher.update(data, 'utf8', 'base64') + cipher.final('base64');
};
exports.decrypt = function (data, key, iv) {
fork icon12
star icon36
watch icon7

+ 2 other calls in file

90
91
92
93
94
95
96
97
98
99
//fields sunt toate celelalte
//in fields proprietatile sunt valorile atributelor name din inputurile din formular
fisierUseri = fs.readFileSync("resources/json/useri.json");
var parolaCriptata;
//al doilea argument e parola(cheia) de criptare
var algoritmCriptare = crypto.createCipher(
  "aes-128-cbc",
  "parola_criptare"
);
parolaCriptata = algoritmCriptare.update(fields.parola, "utf-8", "hex");
fork icon1
star icon5
watch icon0

459
460
461
462
463
464
465
466
467
468
469
470
471




function testCipher1(key) {
  // Test encryption and decryption
  const plaintext = 'Keep this a secret? No! Tell everyone about node.js!';
  const cipher = crypto.createCipher('aes192', key);


  // Encrypt plaintext which is in utf8 format
  // to a ciphertext which will be in hex
  let ciph = cipher.update(plaintext, 'utf8', 'hex');
fork icon0
star icon0
watch icon0

+ 5 other calls in file

-3
-2
-1
exports.createDecipher = exports.Decipher = crypto.createDecipher
exports.createDecipheriv = exports.Decipheriv = crypto.createDecipheriv
exports.listCiphers = exports.getCiphers = crypto.getCiphers
fork icon0
star icon0
watch icon0

274
275
276
277
278
279
280
281
282
with legacy programs that expect `'binary'` to be the default encoding.

New applications should expect the default to be `'buffer'`. This property may
become deprecated in a future Node.js release.

### crypto.createCipher(algorithm, password)

Creates and returns a `Cipher` object that uses the given `algorithm` and
`password`.
fork icon0
star icon0
watch icon1