fork download
  1. process.stdin.resume();
  2. process.stdin.setEncoding('utf8');
  3. 'use strict';
  4.  
  5. const crypto = require('crypto');
  6.  
  7. const ENCRYPTION_KEY = process.env.ENCRYPTION_KEY; // Must be 256 bits (32 characters)
  8. const IV_LENGTH = 16; // For AES, this is always 16
  9.  
  10. function encrypt(text) {
  11. let iv = crypto.randomBytes(IV_LENGTH);
  12. let cipher = crypto.createCipheriv('aes-256-cbc', Buffer.from(ENCRYPTION_KEY), iv);
  13. let encrypted = cipher.update(text);
  14.  
  15. encrypted = Buffer.concat([encrypted, cipher.final()]);
  16.  
  17. return iv.toString('hex') + ':' + encrypted.toString('hex');
  18. }
  19.  
  20. function decrypt(text) {
  21. let textParts = text.split(':');
  22. let iv = Buffer.from(textParts.shift(), 'hex');
  23. let encryptedText = Buffer.from(textParts.join(':'), 'hex');
  24. let decipher = crypto.createDecipheriv('aes-256-cbc', Buffer.from(ENCRYPTION_KEY), iv);
  25. let decrypted = decipher.update(encryptedText);
  26.  
  27. decrypted = Buffer.concat([decrypted, decipher.final()]);
  28.  
  29. return decrypted.toString();
  30. }
  31.  
  32. module.exports = { decrypt, encrypt };
Success #stdin #stdout 0.07s 37144KB
stdin
bnkjgjoa;x,/.mv.m
stdout
Standard output is empty