-
-function generatePassword (callback) {
- crypto.randomBytes(32, function (err, buf) {
- if (err) return callback(err)
-
- callback(null, buf.toString('utf8'))
- })
-}
-
-function symetricDecrypt (text, password) {
- const decipher = crypto.createDecipher(algorithm, password)
- let dec = decipher.update(text, 'hex', 'utf8')
- dec += decipher.final('utf8')
- return dec
-}
-
-function symetricEncrypt (text, callback) {
- generatePassword(function (err, password) {
- if (err) return callback(err)
-
- const cipher = crypto.createCipher(algorithm, password)
- let crypted = cipher.update(text, 'utf8', 'hex')
- crypted += cipher.final('hex')
- callback(null, { crypted: crypted, password: password })
- })
-}