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); */
expect(next.mock.calls[0][1]).toEqual(Buffer.concat([encrypter.update("plaintext data"), encrypter.final()]));
expect(next.mock.calls[0][1]).toEqual(Buffer.concat([encrypter.update("plaintext data"), encrypter.final()]));
const receive = mw.transporterReceive.call(broker, next);
const encrypter = crypto.createCipher("aes-256-cbc", password);
const encryptedData = Buffer.concat([encrypter.update("plaintext data"), encrypter.final()]);
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;
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 encrypt (plaintext) { var encipher = crypto.createCipher(algorithm, 'pw') var ciphertext = encipher.update(plaintext, 'utf8', 'hex') ciphertext += encipher.final('hex') return ciphertext
function encrypt (content, key) { if (!Buffer.isBuffer(content)) content = new Buffer(content) let encrypted = '' let cip = crypto.createCipher('rc4', key) encrypted += cip.update(content, 'binary', 'hex') encrypted += cip.final('hex') return encrypted
const aesEncrypt = (buffer, mode, key, iv) => { const cipher = crypto.createCipheriv('aes-128-' + mode, key, iv) return Buffer.concat([cipher.update(buffer), cipher.final()])
/** * 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
/** * @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(), 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);
//AES 对称加密算法的一种。 //创建加密算法 function aesEncode(data, key) { const cipher = crypto.createCipher('aes192', key); var crypted = cipher.update(data, 'utf8', 'hex'); crypted += cipher.final('hex'); return crypted;
function encrypt(text){ var cipher = crypto.createCipher(algorithm,password) var crypted = cipher.update(text,'utf8','hex') crypted += cipher.final('hex'); return crypted;
// 80f7e22570... * AES // AES是一种常用的对称加密算法,加解密都用同一个密钥。crypto模块提供了AES支持,但需要自己封装好函数,便于使用 function aesEncrypt(data, key) {