Last active
January 27, 2021 08:31
-
-
Save Avi-E-Koenig/9b0539a34068117aa3d463a5f2b60066 to your computer and use it in GitHub Desktop.
Encrypt/decrypt with aes
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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