lib/account.js
function (password, opts) {
        /*jshint maxcomplexity:17 */

        opts = opts || {};
        var salt = opts.salt || cryptoUtils.crypto.randomBytes(32);
        var iv = opts.iv || cryptoUtils.crypto.randomBytes(16);
        var derivedKey;
        var kdf = opts.kdf || 'scrypt';
        var kdfparams = {
            dklen: opts.dklen || 32,
            salt: salt.toString('hex')
        };
        if (kdf === 'pbkdf2') {
            kdfparams.c = opts.c || 262144;
            kdfparams.prf = 'hmac-sha256';
            derivedKey = cryptoUtils.crypto.pbkdf2Sync(new Buffer(password), salt, kdfparams.c, kdfparams.dklen, 'sha256');
        } else if (kdf === 'scrypt') {
            kdfparams.n = opts.n || 4096;
            kdfparams.r = opts.r || 8;
            kdfparams.p = opts.p || 1;
            derivedKey = cryptoUtils.scrypt(new Buffer(password), salt, kdfparams.n, kdfparams.r, kdfparams.p, kdfparams.dklen);
        } else {
            throw new Error('Unsupported kdf');
        }
        var cipher = cryptoUtils.crypto.createCipheriv(opts.cipher || 'aes-128-ctr', derivedKey.slice(0, 16), iv);
        if (!cipher) {
            throw new Error('Unsupported cipher');
        }
        var ciphertext = Buffer.concat([cipher.update(this.privKey), cipher.final()]);
        // var mac = cryptoUtils.sha3(Buffer.concat([derivedKey.slice(16, 32), new Buffer(ciphertext, 'hex')]));   // KeyVersion3 deprecated
        var mac = cryptoUtils.sha3(Buffer.concat([derivedKey.slice(16, 32), new Buffer(ciphertext, 'hex'), iv, new Buffer(opts.cipher || 'aes-128-ctr')]));
        return {
            version: KeyCurrentVersion,
            id: cryptoUtils.uuid.v4({
                random: opts.uuid || cryptoUtils.crypto.randomBytes(16)
            }),
            address: this.getAddressString(),
            crypto: {
                ciphertext: ciphertext.toString('hex'),
                cipherparams: {
                    iv: iv.toString('hex')
                },
                cipher: opts.cipher || 'aes-128-ctr',
                kdf: kdf,
                kdfparams: kdfparams,
                mac: mac.toString('hex'),
                machash: "sha3256"
            }
        };
    }
function (password, opts) {
        /*jshint maxcomplexity:17 */

        opts = opts || {};
        var salt = opts.salt || cryptoUtils.crypto.randomBytes(32);
        var iv = opts.iv || cryptoUtils.crypto.randomBytes(16);
        var derivedKey;
        var kdf = opts.kdf || 'scrypt';
        var kdfparams = {
            dklen: opts.dklen || 32,
            salt: salt.toString('hex')
        };
        if (kdf === 'pbkdf2') {
            kdfparams.c = opts.c || 262144;
            kdfparams.prf = 'hmac-sha256';
            derivedKey = cryptoUtils.crypto.pbkdf2Sync(new Buffer(password), salt, kdfparams.c, kdfparams.dklen, 'sha256');
        } else if (kdf === 'scrypt') {
            kdfparams.n = opts.n || 4096;
            kdfparams.r = opts.r || 8;
            kdfparams.p = opts.p || 1;
            derivedKey = cryptoUtils.scrypt(new Buffer(password), salt, kdfparams.n, kdfparams.r, kdfparams.p, kdfparams.dklen);
        } else {
            throw new Error('Unsupported kdf');
        }
        var cipher = cryptoUtils.crypto.createCipheriv(opts.cipher || 'aes-128-ctr', derivedKey.slice(0, 16), iv);
        if (!cipher) {
            throw new Error('Unsupported cipher');
        }
        var ciphertext = Buffer.concat([cipher.update(this.privKey), cipher.final()]);
        // var mac = cryptoUtils.sha3(Buffer.concat([derivedKey.slice(16, 32), new Buffer(ciphertext, 'hex')]));   // KeyVersion3 deprecated
        var mac = cryptoUtils.sha3(Buffer.concat([derivedKey.slice(16, 32), new Buffer(ciphertext, 'hex'), iv, new Buffer(opts.cipher || 'aes-128-ctr')]));
        return {
            version: KeyCurrentVersion,
            id: cryptoUtils.uuid.v4({
                random: opts.uuid || cryptoUtils.crypto.randomBytes(16)
            }),
            address: this.getAddressString(),
            crypto: {
                ciphertext: ciphertext.toString('hex'),
                cipherparams: {
                    iv: iv.toString('hex')
                },
                cipher: opts.cipher || 'aes-128-ctr',
                kdf: kdf,
                kdfparams: kdfparams,
                mac: mac.toString('hex'),
                machash: "sha3256"
            }
        };
    }
function ( password , opts ) { /*jshint maxcomplexity:17 */ opts = opts || { } ; var salt = opts . salt || cryptoUtils . crypto . randomBytes ( 32 ) ; var iv = opts . iv || cryptoUtils . crypto . randomBytes ( 16 ) ; var derivedKey ; var kdf = opts . kdf || 'scrypt' ; var kdfparams = { dklen : opts . dklen || 32 , salt : salt . toString ( 'hex' ) } ; if ( kdf === 'pbkdf2' ) { kdfparams . c = opts . c || 262144 ; kdfparams . prf = 'hmac-sha256' ; derivedKey = cryptoUtils . crypto . pbkdf2Sync ( new Buffer ( password ) , salt , kdfparams . c , kdfparams . dklen , 'sha256' ) ; } else if ( kdf === 'scrypt' ) { kdfparams . n = opts . n || 4096 ; kdfparams . r = opts . r || 8 ; kdfparams . p = opts . p || 1 ; derivedKey = cryptoUtils . scrypt ( new Buffer ( password ) , salt , kdfparams . n , kdfparams . r , kdfparams . p , kdfparams . dklen ) ; } else { throw new Error ( 'Unsupported kdf' ) ; } var cipher = cryptoUtils . crypto . createCipheriv ( opts . cipher || 'aes-128-ctr' , derivedKey . slice ( 0 , 16 ) , iv ) ; if ( ! cipher ) { throw new Error ( 'Unsupported cipher' ) ; } var ciphertext = Buffer . concat ( [ cipher . update ( this . privKey ) , cipher . final ( ) ] ) ; // var mac = cryptoUtils.sha3(Buffer.concat([derivedKey.slice(16, 32), new Buffer(ciphertext, 'hex')]));   // KeyVersion3 deprecated var mac = cryptoUtils . sha3 ( Buffer . concat ( [ derivedKey . slice ( 16 , 32 ) , new Buffer ( ciphertext , 'hex' ) , iv , new Buffer ( opts . cipher || 'aes-128-ctr' ) ] ) ) ; return { version : KeyCurrentVersion , id : cryptoUtils . uuid . v4 ( { random : opts . uuid || cryptoUtils . crypto . randomBytes ( 16 ) } ) , address : this . getAddressString ( ) , crypto : { ciphertext : ciphertext . toString ( 'hex' ) , cipherparams : { iv : iv . toString ( 'hex' ) } , cipher : opts . cipher || 'aes-128-ctr' , kdf : kdf , kdfparams : kdfparams , mac : mac . toString ( 'hex' ) , machash : "sha3256" } } ; }
Generate key buy passphrase and options.

@param {Password} password - Provided password.
@param {KeyOptions} opts - Key options.

@return {Key} Key Object.

@example var key = account.toKey("passphrase");
Generate key buy passphrase and options .