self.encrypt = function(data, key) { var cipher = crypto.createCipheriv(algorithm, new Buffer(key), ''); cipher.setAutoPadding(false); try { return new Buffer(cipher.update(pad(data), 'utf8', 'binary') + cipher.final('binary'), 'binary').toString('base64'); } catch (e) { return null; } }
function createCipher(options) { 'use strict'; if (_.isString(options.key)) { return crypto.createCipher(options.cipher, options.key); } else { var iv = crypto.createHash('md5').update(options.seed).digest('hex'); return crypto.createCipheriv(options.cipher, options.key, iv); } };
const encrypt = async (key, text) => { if (!Buffer.isBuffer(key)) key = Buffer.from(key, 'hex') const iv = await createIv() const cipher = crypto.createCipheriv(algorithm, key, iv) const encrypted = cipher.update(text) return Buffer.concat([encrypted, cipher.final(), iv]).toString('hex') }
const encrypt = (inputData, config) => { const iv = crypto.randomBytes(12) const cipher = crypto.createCipheriv('aes-256-gcm', config.settings.cipher.key, iv) let data = cipher.update(JSON.stringify(inputData, null, 2), 'utf8', 'base64') data += cipher.final('base64') const auth = cipher.getAuthTag() return [iv.toString('hex'), auth.toString('hex'), data].join(config.settings.cipher.separator) }
// give us ciphertext for this plaintext. // note that this way of using the block cipher is only intended for the // specific purpose outlined in this module. function encrypt(key, iv, plaintext) { var cipher = crypto.createCipheriv('aes-256-cfb8', key, iv); var ciphertext = cipher.update(plaintext); var finaltext = cipher.final(); assert.equal(finaltext.length, 0); if (typeof ciphertext === "string") { ciphertext = new Buffer(ciphertext, 'binary'); } return ciphertext; }
export function createCipher(secret, methodName, initialData, _iv) { const key = generateKey(methodName, secret); const iv = _iv || crypto.randomBytes(getParamLength(methodName)[1]); const cipher = crypto.createCipheriv(methodName, key, iv); return { cipher, data: Buffer.concat([iv, cipher.update(initialData)]), }; }
function encrypt(text) { var cipher = crypto.createCipheriv(algorithm, key, iv); var encrypted = cipher.update(text, 'utf8', 'hex'); encrypted += cipher.final('hex'); var tag = cipher.getAuthTag(); return { content: encrypted, tag: tag }; }
exports.aesEncrypt = function(data, key) { var iv = ''; var clearEncoding = 'utf8'; var cipherEncoding = 'base64'; var cipher = crypto.createCipheriv('aes-128-ecb', key, iv); var cipherChunks = []; cipherChunks.push(cipher.update(data, clearEncoding, cipherEncoding)); cipherChunks.push(cipher.final(cipherEncoding)); return cipherChunks.join(''); };
providers.getRaw(providerName, function(err, providerRaw) { assert(!err, err); var cipher = crypto.createCipheriv('aes-256-cbc', providerRaw.crypto_key, providerRaw.crypto_iv); var enc = Buffer.concat([cipher.update(new Buffer(body, 'hex')), cipher.final()]); ls.database.query('SELECT license FROM licenses WHERE provider_id = ? AND content_id = ? AND sequence_id = ?', [providerRaw.id, contentId, sequenceId], function(err, result) { assert(!err, err); assert(enc.equals(result[0].license), 'Encrypted again license not equal to database original'); done(); }); });
function calc_resp(password_hash, server_challenge){ // padding with zeros to make the hash 21 bytes long var passHashPadded = new Buffer(21); passHashPadded.fill("\0"); password_hash.copy(passHashPadded, 0, 0, password_hash.length); var resArray = []; var des = crypto.createCipheriv('DES-ECB', insertZerosEvery7Bits(passHashPadded.slice(0,7)), ''); resArray.push( des.update(server_challenge.slice(0,8)) ); des = crypto.createCipheriv('DES-ECB', insertZerosEvery7Bits(passHashPadded.slice(7,14)), ''); resArray.push( des.update(server_challenge.slice(0,8)) ); des = crypto.createCipheriv('DES-ECB', insertZerosEvery7Bits(passHashPadded.slice(14,21)), ''); resArray.push( des.update(server_challenge.slice(0,8)) ); return Buffer.concat(resArray); }
exports.encrypt = function(text,callBack) { var cipher = crypto.createCipheriv(algorithm, password, iv); var encrypted = cipher.update(text, 'utf8', 'hex'); encrypted += cipher.final('hex'); // var tag = cipher.getAuthTag(); callBack({ content: encrypted // tag: tag }); };
function encrypt(text, password) { var hash = crypto.createHash('sha1'); hash.update(password); var key = hash.digest().slice(0, 16); var ivBuffer = Buffer.alloc(16); var cipher = crypto.createCipheriv(algorithm, key, ivBuffer); var crypted = cipher.update(text, 'utf8', 'hex'); crypted += cipher.final('hex'); return crypted; }
var encrypt_gcm = function (plain, secret, iv) { var cipher, encrypt = crypto.createCipheriv('aes-256-gcm', secret, iv); cipher = encrypt.update(plain, 'utf8', 'base64'); cipher += encrypt.final('base64'); return { content: cipher, tag: encrypt.getAuthTag() }; };
// encrypt the packet function lineize(to, packet) { var wrap = {type:"line"}; wrap.line = to.lineIn; var iv = crypto.randomBytes(16); wrap.iv = iv.toString("hex"); var aes = crypto.createCipheriv("AES-256-CTR", to.encKey, iv); var body = Buffer.concat([aes.update(pencode(packet.js,packet.body)), aes.final()]); return pencode(wrap,body); }
function makeResponse(hash, nonce) { var out = new Buffer(24); for ( var i = 0; i < 3; i++) { var keybuf = $.oddpar($.expandkey(hash.slice(i * 7, i * 7 + 7))); var des = crypto.createCipheriv('DES-ECB', keybuf, ''); var str = des.update(nonce, 'binary', 'binary'); out.write(str, i * 8, i * 8 + 8, 'binary'); } return out; }
var transformKey = function(key, seed, rounds) { for(var round = 0; round < rounds; round++) { var cipher = crypto.createCipheriv('aes-256-ecb', seed, new Buffer(0)); cipher.setAutoPadding(false); key = cipher.update(key, 'binary', 'binary') + cipher.final('binary'); } key = crypto.createHash('sha256').update(key, 'binary').digest('binary'); return key; }
crypto.pbkdf2(this.passphrase, salt, this.options.rounds, 48, function(err, keyiv) { if (err) { throw(err); } this.passphrase = null; this.cipher = crypto.createCipheriv("aes256", keyiv.slice(0, 32), keyiv.slice(32)); this.push(salt); this.push(this.cipher.update(chunk)); done(); }.bind(this));
function send_data(obj) { var aes_iv = crypto.randomBytes(16); var cipher = crypto.createCipheriv('aes-256-cbc', AES_KEY, aes_iv); var objdata = msgpack.pack(obj); var buffer = [cipher.update(objdata), cipher.final()]; var data = [TOKEN, aes_iv.toString('hex'), objdata.length, Buffer.concat(buffer)]; sock.send(msgpack.pack(data)); }
exports.validate = function(){ if(!ecc || !ursa) return false; try { var eccKey = new ecc.ECKey(ecc.ECCurves.nistp256); var aes = crypto.createCipheriv("AES-256-CTR", crypto.randomBytes(32), crypto.randomBytes(16)); }catch(E){}; if(!eccKey || !aes) return false; return true; }
module.exports.generateLangFile = function(generateData, cb){ var file = generateData.outDir + module.exports.DIR_LANG + generateData.lang + module.exports.LANG_EXT; //words.getWords(pg, lang, lesson, function(words){ var data = generateData.lesson + ';' + generateData.lang + ';' + generateData.words.length + '\n'; generateData.words.forEach(function(w,idx){ data += w.link + ";"; data += w.word + ";"; generateData.images.some(function(image,ii){ if(w.link == image.lid){ if(realImageFile(image)){ data += image.imagefile; } return; } }); data += "\n"; }); if(Config.debug){ console.log('word', data); } var crypto = require('crypto'); //console.log(crypto.getCiphers(), crypto.getHashes()); var algorithm = 'aes-128-cbc'; // or any other algorithm supported by OpenSSL var key = 'password'; var buffKey = new Buffer(Config.PKG_KEY); var iv = new Buffer(Config.PKG_INIT_KEY); var cipher = crypto.createCipheriv(algorithm, buffKey, iv); var encrypted = cipher.update(data, 'utf8', 'hex') + cipher.final('hex'); //console.log('to tech dat moc neni ne?', data, file); fs.writeFile(file, encrypted, function (err) { cb(err); }); //}); }
//加密 function encrypt() { //encrypt var cipher = crypto.createCipheriv(alg, key, iv); if(autoPad){ cipher.setAutoPadding(autoPad) //default true } var ciph = cipher.update(plaintext, 'utf8', 'hex'); ciph += cipher.final('hex'); // console.log(alg, ciph) return ciph; }
Auth.prototype.__encrypt = function(plaintext) { var crypto = require("crypto"); var shasum = crypto.createHash('md5'); shasum.update(this.Config.encryption_key); var hashed_key = shasum.digest("hex"); var iv = crypto.randomBytes(8).toString('hex'); var cipher = crypto.createCipheriv("aes-256-cbc", hashed_key, iv); cipher.setAutoPadding(true); var encrypted = cipher.update(plaintext, "binary", "hex") + cipher["final"]("hex"); return iv + encrypted; };
/** * Encrypts password. * * @param {string} plainText - password. */ encrypt(plainText) { const IV = new Buffer(crypto.randomBytes(this.config.iv_length)); const encryptor = crypto.createCipheriv(this.config.algorithm, this.config.key, IV); encryptor.setEncoding('hex'); encryptor.write(plainText); encryptor.end(); const cipherText = encryptor.read(); return `${cipherText}:${IV.toString('hex')}`; };
function encrypt(plaintext, key, iv) { iv = iv.slice(0, 16); var cipher = crypto.createCipheriv('aes-256-cbc', key, iv); cipher.setAutoPadding(true); var ciphertext = cipher.update(plaintext, 'utf8', 'base64'); ciphertext += cipher.final('base64'); console.log('ciphertext', ciphertext, ciphertext.length); return ciphertext; }
function sendEncryptionKeyResponse() { var pubKey = mcPubKeyToURsa(packet.publicKey); var encryptedSharedSecretBuffer = pubKey.encrypt(sharedSecret, undefined, undefined, ursa.RSA_PKCS1_PADDING); var encryptedVerifyTokenBuffer = pubKey.encrypt(packet.verifyToken, undefined, undefined, ursa.RSA_PKCS1_PADDING); client.cipher = crypto.createCipheriv('aes-128-cfb8', sharedSecret, sharedSecret); client.decipher = crypto.createDecipheriv('aes-128-cfb8', sharedSecret, sharedSecret); client.write(0xfc, { sharedSecret: encryptedSharedSecretBuffer, verifyToken: encryptedVerifyTokenBuffer, }); }
function encrypt(buffer, password) { password = Buffer.from(password); var cipher = crypto.createCipheriv('aes-256-ctr', crypto.pbkdf2Sync(password, '', 100000, 32, 'sha512'), crypto.createHash('sha1').update(password).digest().slice(0, 16)); var arrChunks = []; var CHUNK_LENGTH = 2003; for (var offset = 0; offset < buffer.length; offset += CHUNK_LENGTH) { arrChunks.push(cipher.update(buffer.slice(offset, Math.min(offset + CHUNK_LENGTH, buffer.length)), 'utf8')); } arrChunks.push(cipher.final()); return Buffer.concat(arrChunks); }
exports.generateKey(password, options, function (err, key) { if (err) { return callback(err); } var cipher = Crypto.createCipheriv(options.algorithm, key.key, key.iv); var enc = Buffer.concat([cipher.update(data, 'utf8'), cipher.final()]); callback(null, enc, key); });
NodeJs.prototype.encryptData = function(data, key, vector) { if (this.$benchmark) var s = Date.now(); var keyBuffer = (new Buffer(key, "base64")).slice(0, 16); var ivBuffer = (new Buffer(vector, "base64")).slice(0, 16); var dataBuffer = new Buffer(data, "utf8"); var cipher = crypto.createCipheriv("aes-128-ctr", keyBuffer, ivBuffer); var cdataBuffer = cipher.update(dataBuffer); var r = cdataBuffer.toString("base64"); if (this.$benchmark) console.log("BENCHMARK crypto/NodeJs encryptData took "+(Date.now()-s)+" ms"); return r; }
function contentEncryption(dataEncryptionAlgorithm, key, plainText, authenticatedData) { checkDataEncryptionAlgorithm(dataEncryptionAlgorithm); var iv = Random.generateRandomNumber(16); var cipher = Crypto.createCipheriv('AES-128-CBC', key.subarray(16), iv); var partial = new Uint8Array(cipher.update(plainText)); var cipherText = ByteArray.add(partial, new Uint8Array(cipher.final())); return { cipherText: cipherText, iv: iv, tag: getTag(key, cipherText, iv, authenticatedData) }; }
encrypt(text, appid){ text = new Buffer(text); var pad = enclen(text.length), pack = new PKCS7().encode(20 + text.length + appid.length), random = getRandomStr(), content = random + pad + text.toString('binary') + appid + pack; var cipher = crypto.createCipheriv(this.mode, this.key, this.key.slice(0, 16)); cipher.setAutoPadding(false); return cipher.update(content, 'binary', 'base64') + cipher.final('base64'); }