(message, secret)
| 42 | } |
| 43 | |
| 44 | function encrypt(message, secret) { |
| 45 | const iv = crypto.randomBytes(IV); |
| 46 | const salt = crypto.randomBytes(SALT); |
| 47 | const key = crypto.pbkdf2Sync(secret, salt, ITER, KEYLEN, DIGEST); |
| 48 | const cipher = crypto.createCipheriv('aes-256-gcm', key, iv, { authTagLength: TAG }); |
| 49 | const enc = Buffer.concat([cipher.update(String(message), 'utf-8'), cipher.final()]); |
| 50 | return Buffer.concat([salt, cipher.getAuthTag(), iv, enc]); |
| 51 | } |
| 52 | function decrypt(buf, secret) { |
| 53 | const salt = buf.subarray(0, SALT); |
| 54 | const tag = buf.subarray(SALT, SALT + TAG); |
no test coverage detected