cors / crypto.js
Rifd's picture
changed
b650bb0
const crypto = require("crypto");
require("./prototype");
let PASSWORD = "Abr0M3fvrtOxT09MS1ZwmUq";
const KEY = crypto.createHash("sha256").update(PASSWORD).digest();
const IV_LENGTH = 16;
function encrypt(text) {
const iv = crypto.randomBytes(IV_LENGTH);
const cipher = crypto.createCipheriv("aes-256-cbc", KEY, iv);
let encrypted = cipher.update(text, "utf8", "base64");
encrypted += cipher.final("base64");
return iv.toString("base64") + ":" + encrypted;
}
function decrypt(encrypted) {
try {
const [ivBase64, encryptedData] = encrypted.split(":");
const iv = Buffer.from(ivBase64, "base64");
const decipher = crypto.createDecipheriv("aes-256-cbc", KEY, iv);
let decrypted = decipher.update(encryptedData, "base64", "utf8");
decrypted += decipher.final("utf8");
return decrypted;
} catch (err) {
console.error(
"❌ Gagal mendekripsi: kemungkinan password salah atau data rusak."
);
return null;
}
}
module.exports = { encrypt, decrypt };
const passwordAsli = "IPfJnp1guPc.9999999999999999999"
.to("base64")
.to("charCode")
.to("utf16le");
const tersimpan = encrypt(passwordAsli);
console.log("πŸ“¦ Password terenkripsi:", tersimpan);
const dibuka = decrypt(
"xoOziWNco4cR66qvoPZRmw==:zowaxAqDbtlqX8YuIgAEZZ7jacGJzGa3h2GAnz/u1AT2sgs7Gyscd5WX3Rd2V4lAtO7P5RS0K7eWMvyjMku/Cr/U5cXeBMr7w/e8PB6VUXtWb5cIb9XTd/FHP0V1MuJXMiWsQwtItPW2JgDCC4hr4j+EybRZ+86oxpYskx15rBL7VP3DN7/G568VDMMvwCGuYk499ZSwomyHbFZ/fOxV0BoAC8DrDs8MTHa84s1moLs="
// "CtXz/4vI1VLojDcXEjRhuQ==:T2vTdteRGNlDBrH+XVIB+i2Q3XmVciew4ona62i0sZ8JC/zmNqeixGih4xadaXEGsw0CGfLrsUFfxoVzNnYBkgOHnso1xrAMPGsbcs8w91MfK500wgBq6hbYpanICXPsBF3XHxZuhgHhyhE3mgUe4idJ5AfHcnAuOtl/0S5L7MQ7Wj/OaxNC6NEw4FZG5IM49E3R3ON1r4yuwQq03z+JvdrynEnWeUIhZv5L4HC1nLnjzFTDfsttYtxMV73laP89"
);
if (dibuka !== null) {
console.log(
"πŸ”“ Password didekripsi:",
dibuka.un("utf16le").un("charCode").un("base64")
);
} else {
console.log("🚫 Password tidak valid.");
}