mirror of
https://github.com/mohamadihsan/topuponline.git
synced 2026-12-06 23:36:28 +00:00
35 lines
688 B
JavaScript
35 lines
688 B
JavaScript
const CryptoJS = require("crypto-js");
|
|
|
|
// ENCRYPT TEXT
|
|
const encryptText = (text) => {
|
|
try {
|
|
return CryptoJS.AES.encrypt(text, process.env.SECRET_KEY).toString();
|
|
} catch (error) {
|
|
return error.message;
|
|
}
|
|
};
|
|
|
|
// DECRYPT TEXT
|
|
const decryptText = (cipherText) => {
|
|
try {
|
|
return CryptoJS.AES.decrypt(cipherText, process.env.SECRET_KEY).toString(
|
|
CryptoJS.enc.Utf8
|
|
);
|
|
} catch (error) {
|
|
return error.message;
|
|
}
|
|
};
|
|
|
|
// RANDOM UNIQUE CODE
|
|
function getUniqueCode() {
|
|
const maxDate = Date.now();
|
|
const timestamp = Math.floor(Math.random() * maxDate).toString();
|
|
return timestamp;
|
|
}
|
|
|
|
module.exports = {
|
|
encryptText,
|
|
decryptText,
|
|
getUniqueCode,
|
|
};
|