Answers for "crypto encode decoed nodejs"

0

crypto encode decoed nodejs

const crypto = require('crypto')

const algorithm = 'aes-256-cbc'
const initVector = crypto.randomBytes(16)
const Securitykey = crypto.randomBytes(32)

exports.encrypt = (data) => {
	const cipher = crypto.createCipheriv(algorithm, Securitykey, initVector)
	let encryptedData = cipher.update(data, 'utf-8', 'hex')
	encryptedData += cipher.final('hex')
	return encryptedData
}

exports.decrypt = (data) => {
	const decipher = crypto.createDecipheriv(algorithm, Securitykey, initVector)
	let decryptedData = decipher.update(data, 'hex', 'utf-8')
	decryptedData += decipher.final('utf-8')
	return decryptedData
}
Posted by: Guest on August-09-2021

Code answers related to "Javascript"

Browse Popular Code Answers by Language