Scripts & Codes pentester
  • Stronger Encryption and Decryption in Node.js
  • recon.sh
  • encode_decode.py
  • les.sh
  • suid.sh
  • basicforensiclinuxscript.sh
  • winrmrecon.py
  • WPAnalytics.php
  • Power Recon
  • Reverse Shells
  • cvemap_wrapper.ps1
  • wfuzz_crack_form_login.sh
Powered by GitBook
On this page

Stronger Encryption and Decryption in Node.js

Nextrecon.sh

Last updated 1 year ago

'use strict';

const crypto = require('crypto');

const ENCRYPTION_KEY = process.env.ENCRYPTION_KEY; // Must be 256 bits (32 characters)
const IV_LENGTH = 16; // For AES, this is always 16

function encrypt(text) {
 let iv = crypto.randomBytes(IV_LENGTH);
 let cipher = crypto.createCipheriv('aes-256-cbc', Buffer.from(ENCRYPTION_KEY), iv);
 let encrypted = cipher.update(text);

 encrypted = Buffer.concat([encrypted, cipher.final()]);

 return iv.toString('hex') + ':' + encrypted.toString('hex');
}

function decrypt(text) {
 let textParts = text.split(':');
 let iv = Buffer.from(textParts.shift(), 'hex');
 let encryptedText = Buffer.from(textParts.join(':'), 'hex');
 let decipher = crypto.createDecipheriv('aes-256-cbc', Buffer.from(ENCRYPTION_KEY), iv);
 let decrypted = decipher.update(encryptedText);

 decrypted = Buffer.concat([decrypted, decipher.final()]);

 return decrypted.toString();
}

module.exports = { decrypt, encrypt };
encryption.js
By Morgan Bin Bash
Page cover image