RunKit + npm: lodash

node v10.14.1
endpointsharetweet
const { createCipheriv, createDecipheriv, randomBytes } = require('crypto') const cleartext = '+33983450176' const algorithm = 'aes-256-cbc' const key = process.env.PII_KEY || 'ccb0d435a362061c313fd4ffd5610d68' // 1. Cipher! const iv = randomBytes(16) const cipher = createCipheriv(algorithm, key, iv) const obscured = iv.toString('hex') + ':' + cipher.update(cleartext, 'utf8', 'hex') + cipher.final('hex') console.log(cleartext, 'becomes', obscured) // 2. Decipher! const parts = obscured.split(':') const iv2 = Buffer.alloc(16, parts[0], 'hex') const obscured2 = Buffer.alloc(parts[1].length / 2, parts[1], 'hex') const decipher = createDecipheriv(algorithm, key, iv2) const cleartext2 = decipher.update(obscured2) + decipher.final() console.log(obscured, 'becomes', cleartext2)
Created from: https://npm.runkit.com/lodash
Loading…