encrypt(ctx) { const encrypt = crypto.createCipheriv("aes-256-ctr", pass, iv); return ctx.params.pipe(encrypt); }
transporterSend(next) { return (topic, data, meta) => { const encrypter = iv ? crypto.createCipheriv(algorithm, password, iv) : crypto.createCipher(algorithm, password); const res = Buffer.concat([encrypter.update(data), encrypter.final()]); return next(topic, res, meta); }; }
// For a given config object, filename, and data, store a file // Returns a promise async createFile(filename, data, contentType, options = {}) { const bucket = await this._getBucket(); const stream = await bucket.openUploadStream(filename, { metadata: options.metadata }); if (this._fileKey !== null) { const iv = crypto.randomBytes(16); const cipher = crypto.createCipheriv(this._algorithm, this._fileKey, iv); const encryptedResult = Buffer.concat([cipher.update(data), cipher.final(), iv, cipher.getAuthTag()]); await stream.write(encryptedResult); } else { await stream.write(data); } stream.end(); return new Promise((resolve, reject) => { stream.on('finish', resolve); stream.on('error', reject); }); }
/** * @description Generate a gateway key. * @param {string} token - Gateway token. * @param {string} password - Gateway password. * @returns {string} - Return the key. * @example * const key = generateGatewayKey('KLJKJKlkj', 'KJSKDLFJ'); */ function generateGatewayKey(token, password) { const cipher = crypto.createCipheriv('aes-128-cbc', password, AQARA_IV); return cipher.update(token, 'ascii', 'hex'); /* const cipher = crypto.createCipheriv('aes128', password, Buffer.from('17996d093d28ddb3ba695a2e6f58562e', 'hex')); let encodedString = cipher.update(token, 'utf8', 'hex'); encodedString += cipher.final('hex'); return encodedString.substring(0, 32); */ }
const next = jest.fn(); const send = mw.transporterSend.call(broker, next); const encrypter = crypto.createCipheriv("aes-256-ctr", pass, iv); const next = jest.fn(); const receive = mw.transporterReceive.call(broker, next); const encrypter = crypto.createCipheriv("aes-256-ctr", pass, iv); const encryptedData = Buffer.concat([encrypter.update("plaintext data"), encrypter.final()]);
/** * Encrypts data. * @param {Object} options * @param {String} options.data data to encrypt * @param {Boolean} [options.base64=true] `true` to return result in Base64 * @example * TuyaCipher.encrypt({data: 'hello world'}) * @returns {Buffer|String} returns Buffer unless options.base64 is true */ encrypt(options) { const cipher = crypto.createCipheriv('aes-128-ecb', this.key, ''); let encrypted = cipher.update(options.data, 'utf8', 'base64'); encrypted += cipher.final('base64'); // Default base64 enable if (options.base64 === false) { return Buffer.from(encrypted, 'base64'); } return encrypted; }
encrypt(readableStream, key, iv) { this.validateKey(key) if (iv.length !== 16) { throw new Error(`encrypt iv must be exactly 16 bytes, but received ${iv.length}`) } const cipher = crypto.createCipheriv(ALGORITHM, Buffer.from(key, 'hex'), iv) readableStream.pipe(cipher) return cipher }
const encryptedOrderSignature = (ebicsAccount, document, transactionKey, key, xmlOptions) => { const dst = zlib.deflateSync(orderSignature(ebicsAccount, document, key, xmlOptions)); const cipher = crypto.createCipheriv('aes-128-cbc', transactionKey, Buffer.from([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0])).setAutoPadding(false); return Buffer.concat([cipher.update(Crypto.pad(dst)), cipher.final()]).toString('base64'); }
function createEncgz (secret, iv) { const cipherKey = createCipherKey(secret) const encryptStream = createCipheriv('aes256', cipherKey, iv) const gzipStream = createGzip() const stream = pumpify(encryptStream, gzipStream) return stream }
export function encryptSettingsCache(data){ let args = [Buffer.from(key[1], "base64"), Buffer.from(key[0], "base64")] let cipher = crypto.createCipheriv('aes-256-cbc', ...args); let encrypted = cipher.update(Buffer.from(data, "utf8")); encrypted = Buffer.concat([encrypted, cipher.final()]); return encrypted.toString("base64") }
function aesEncrypt(text, secKey) { const _text = text const lv = new Buffer('0102030405060708', 'binary') const _secKey = new Buffer(secKey, 'binary') const cipher = crypto.createCipheriv('AES-128-CBC', _secKey, lv) let encrypted = cipher.update(_text, 'utf8', 'base64') encrypted += cipher.final('base64') return encrypted }
/** * Encrypts text * @param {string} text - text to encrypt */ encrypt(text) { const cipher = crypto.createCipheriv(algorithm, key, iv) let encrypted = cipher.update(text, 'utf8', 'hex') encrypted += cipher.final('hex') return encrypted }
encrypt(ctx) { const encrypter = crypto.createCipheriv("aes-256-ctr", password, iv); return ctx.params.pipe(encrypter); }
/** * @description Generate a gateway key. * @param {string} token - Gateway token. * @param {string} password - Gateway password. * @returns {string} - Return the key. * @example * const key = generateGatewayKey('KLJKJKlkj', 'KJSKDLFJ'); */ function generateGatewayKey(token, password) { const cipher = crypto.createCipheriv('aes-128-cbc', password, AQARA_IV); return cipher.update(token, 'ascii', 'hex'); /* const cipher = crypto.createCipheriv('aes128', password, Buffer.from('17996d093d28ddb3ba695a2e6f58562e', 'hex')); let encodedString = cipher.update(token, 'utf8', 'hex'); encodedString += cipher.final('hex'); return encodedString.substring(0, 32); */ }
// For a given config object, filename, and data, store a file // Returns a promise async createFile(filename: string, data, contentType, options = {}) { const bucket = await this._getBucket(); const stream = await bucket.openUploadStream(filename, { metadata: options.metadata, }); if (this._fileKey !== null) { const iv = crypto.randomBytes(16); const cipher = crypto.createCipheriv(this._algorithm, this._fileKey, iv); const encryptedResult = Buffer.concat([ cipher.update(data), cipher.final(), iv, cipher.getAuthTag(), ]); await stream.write(encryptedResult); } else { await stream.write(data); } stream.end(); return new Promise((resolve, reject) => { stream.on('finish', resolve); stream.on('error', reject); }); }