decrypt(encodedString) { let encoded = JSON.parse(this.constructor.base64decode(encodedString)); encoded.iv = this.constructor.base64decode(encoded.iv); encoded.value = this.constructor.base64decode(encoded.value, 'binary'); const decipher = Crypto.createDecipheriv(this.server.clientOptions.crypt.cypher, this.server.clientOptions.crypt.key, encoded.iv); let decrypted = decipher.update(encoded.value, 'binary', 'ascii'); decrypted += decipher.final('ascii'); return JSON.parse(decrypted); }
const decrypt = (data, algorithm, passphrase) => { data = (Buffer.from(data, 'base64')).toString(); const decipher = crypto.createDecipher(algorithm, passphrase); const decrypted = decipher.update(data, 'hex', 'utf8') + decipher.final('utf8'); return decrypted; }
decrypt(data) { let textParts = data.split(':'), iv = new Buffer(textParts.shift(), 'hex'), encryptedText = new Buffer(textParts.join(':'), 'hex'), decipher = crypto.createDecipheriv(this.algo, new Buffer(this.key), iv), decrypted = decipher.update(encryptedText) decrypted = Buffer.concat([decrypted, decipher.final()]); return decrypted.toString(); }
/** * Decrypt cookie string * * @param {String} str Cookie string * @param {Object} options * @param {Object} options.algorithm Algorithm to use to decrypt data * @param {Object} options.key Key to use to decrypt data * * @return {String} */ function decryptCookie(str, options) { const key = options.key const algorithm = options.algorithm || defaultAlgorithm ensureProperOptions(algorithm, key) const encryptedArray = str.split(':') const iv = new Buffer(encryptedArray[0], 'hex') const encrypted = new Buffer(encryptedArray[1], 'hex') const decipher = crypto.createDecipheriv(algorithm, key, iv) const decrypted = decipher.update(encrypted, 'hex', 'utf8') + decipher.final('utf8') return decrypted }
_.extend({ getKey: function(password) { let keyGenConfig = config.keyGen return crypto.pbkdf2Sync(password, keyGenConfig.salt, keyGenConfig.iterations, keyGenConfig.length, keyGenConfig.digest) }, getPasswordHash: function(password){ let key = this.getKey(password) hash = crypto.createHash('sha256') return hash.update(key).digest('base64') }, encrypt: function(payload, iv, key = config.key, algorithm = config.cipherAlgo){ key = key.slice(0, config.aes.keySize) let cipher = crypto.createCipheriv(algorithm, key, iv) return cipher.update(payload, 'utf8', 'base64') + cipher.final('base64') }, decrypt: function(payload, iv, key = config.key, algorithm = config.cipherAlgo){ key = key.slice(0, config.aes.keySize) let decipher = crypto.createDecipheriv(algorithm, key, iv) return decipher.update(payload, 'base64', 'utf8') + decipher.final('utf8') }, verifyPassword: function(passoword, passwordHash){ return this.getPasswordHash(passoword) == passwordHash } }, crypto)
// 对称解密算法,要求 value 是 String 或 Buffer,否则会报错 const decrypt = (key, value) => { try { let decipher = crypto.createDecipher(config.auth.cipher, key) let result = decipher.update(value, 'hex', 'utf8') result += decipher.final('utf8') return result } catch (e) { return '' } }
const decrypted = decipher.update(text, "binary", "utf8") + decipher.final("utf8");
decipher.setAuthTag(tag); const decrypted = decipher.update(text, "binary", "utf8") + decipher.final("utf8"); return decrypted; });
const decrypt = (data, algorithm, passphrase) => { data = (Buffer.from(data, 'base64')).toString(); const decipher = crypto.createDecipher(algorithm, passphrase); const decrypted = decipher.update(data, 'hex', 'utf8') + decipher.final('utf8'); return decrypted; }
const decrypted = decipher.update(text, "binary", "utf8") + decipher.final("utf8");
decipher.setAuthTag(tag); const decrypted = decipher.update(text, "binary", "utf8") + decipher.final("utf8"); return decrypted; });