From 83e2a5f733c489b369b374813e0cbd4e2509950f Mon Sep 17 00:00:00 2001 From: KOSASIH Date: Fri, 16 Aug 2024 14:11:21 +0700 Subject: [PATCH] Create cryptography.js --- src/utils/cryptography.js | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 src/utils/cryptography.js diff --git a/src/utils/cryptography.js b/src/utils/cryptography.js new file mode 100644 index 000000000..2eb601468 --- /dev/null +++ b/src/utils/cryptography.js @@ -0,0 +1,19 @@ +const crypto = require('crypto'); + +class Cryptography { + static encrypt(data, key) { + const cipher = crypto.createCipher('aes-256-cbc', key); + let encrypted = cipher.update(data, 'utf8', 'hex'); + encrypted += cipher.final('hex'); + return encrypted; + } + + static decrypt(encrypted, key) { + const decipher = crypto.createDecipher('aes-256-cbc', key); + let decrypted = decipher.update(encrypted, 'hex', 'utf8'); + decrypted += decipher.final('utf8'); + return decrypted; + } +} + +module.exports = Cryptography;