Skip to content

Commit

Permalink
Create cryptography.js
Browse files Browse the repository at this point in the history
  • Loading branch information
KOSASIH authored Aug 16, 2024
1 parent 1255b3f commit 83e2a5f
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions src/utils/cryptography.js
Original file line number Diff line number Diff line change
@@ -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;

0 comments on commit 83e2a5f

Please sign in to comment.