MCPcopy Create free account
hub / github.com/codetheweb/tuyapi / _encryptPre34

Method _encryptPre34

lib/cipher.js:54–66  ·  view source on GitHub ↗

* Encrypt data for protocol 3.3 and before * @param {Object} options Options for encryption * @param {String} options.data data to encrypt * @param {Boolean} [options.base64=true] `true` to return result in Base64 * @returns {Buffer|String} returns Buffer unless options.base64 is true

(options)

Source from the content-addressed store, hash-verified

52 * @returns {Buffer|String} returns Buffer unless options.base64 is true
53 */
54 _encryptPre34(options) {
55 const cipher = crypto.createCipheriv('aes-128-ecb', this.getKey(), '');
56
57 let encrypted = cipher.update(options.data, 'utf8', 'base64');
58 encrypted += cipher.final('base64');
59
60 // Default base64 enable
61 if (options.base64 === false) {
62 return Buffer.from(encrypted, 'base64');
63 }
64
65 return encrypted;
66 }
67
68 /**
69 * Encrypt data for protocol 3.4

Callers 1

encryptMethod · 0.95

Calls 1

getKeyMethod · 0.95

Tested by

no test coverage detected