src/cipher.js

Method cipher

Creates a cipher from two input parameters

Parameters:

  • arg must be a String.
    (String to encrypt)

  • encode must be a Boolean.
    ([Optional] Encrypt or decrypt arg using iv, default is true)

  • iv must be a String.
    ([Optional] Initialization vector)

Returns a String
(Result of crypto operation)

TurtleIO.prototype.cipher = function ( arg, encode, iv ) { var cipher, crypted; encode = ( encode !== false ); iv = iv || this.config.session.iv; cipher = crypto[encode ? "createCipher" : "createDecipher"]( "aes-256-cbc", iv ), crypted = encode ? cipher.update( arg, "utf8", "hex" ) : cipher.update( arg, "hex", "utf8" ); crypted += cipher.final( encode ? "hex" : "utf8" ); return crypted; };