Skip to content

Instantly share code, notes, and snippets.

@Avi-E-Koenig
Last active January 27, 2021 08:31
Show Gist options
  • Save Avi-E-Koenig/9b0539a34068117aa3d463a5f2b60066 to your computer and use it in GitHub Desktop.
Save Avi-E-Koenig/9b0539a34068117aa3d463a5f2b60066 to your computer and use it in GitHub Desktop.
Encrypt/decrypt with aes
const CryptoJS = require('crypto-js');
const SECRET_KEYB = process.env.SECRET_KEYB;
class CryptoHandler {
constructor() {
if (!SECRET_KEYB || !SECRET_KEYB.length) {
throw new ErrorHandler(500, 'please see env');
}
}
static encrypt = (param) => {
const output = CryptoJS.AES.encrypt(param, SECRET_KEYB).toString();
return output;
};
static decrypt = (param) => {
const bytes = CryptoJS.AES.decrypt(param, SECRET_KEYB);
return bytes.toString(CryptoJS.enc.Utf8);
};
}
module.exports = CryptoHandler;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment