showing results for - "crypto encode decoed nodejs"
Rayan
22 Jul 2016
1const crypto = require('crypto')
2
3const algorithm = 'aes-256-cbc'
4const initVector = crypto.randomBytes(16)
5const Securitykey = crypto.randomBytes(32)
6
7exports.encrypt = (data) => {
8	const cipher = crypto.createCipheriv(algorithm, Securitykey, initVector)
9	let encryptedData = cipher.update(data, 'utf-8', 'hex')
10	encryptedData += cipher.final('hex')
11	return encryptedData
12}
13
14exports.decrypt = (data) => {
15	const decipher = crypto.createDecipheriv(algorithm, Securitykey, initVector)
16	let decryptedData = decipher.update(data, 'hex', 'utf-8')
17	decryptedData += decipher.final('utf-8')
18	return decryptedData
19}
20