Group: User Level:
Posts: 274 Joined: 9/20/2020 IP-Address: saved
|
// Step 1: Generate the public key Temp const U = "your_username"; const { privateKey: ku, publicKey: pu } = generateKeys(U); const Temp = pu.compress().toString("hex").padStart(64, "0");
// Step 2: Generate the public key Data0 const Data3 = "your_license_type"; const { privateKey: kdata3, publicKey: pdata3 } = generateKeys(Data3); const Data0 = pdata3.compress().toString("hex").padStart(64, "0");
// Step 3: Generate the UID const L = "your_license_key"; const k = Buffer.from("your_private_key", "hex"); // replace with your private key let rl = ""; let sl = ""; while (rl.length === 0 || sl.length === 0 || rl.length > 60 || sl.length > 60) { const { r, s } = sm2.sign(L, k); rl = r.toString("hex"); sl = s.toString("hex"); } const SZrl = rl.padStart(60, "0"); const SZsl = sl.padStart(60, "0"); const UID = SZrl + SZsl;
// Step 4: Generate Data1 const Data1 = "";
// Step 5: Generate Data2 let Temp2 = Temp; let rTemp = ""; let sTemp = ""; while (rTemp.length === 0 || sTemp.length === 0 || rTemp.length > 60 || sTemp.length > 60) { const { r, s } = sm2.sign(Temp2, k); rTemp = r.toString("hex"); sTemp = s.toString("hex"); } const SZrTemp = rTemp.padStart(60, "0"); const SZsTemp = sTemp.padStart(60, "0"); const Data2 = SZrTemp + SZsTemp;
// Step 6: Calculate the checksum const crc32 = require("crc32"); const checksum = crc32(UID + Data0 + Data1 + Data2); const SZchecksum = (4294967295 - checksum).toString().padStart(10, "0");
// Step 7: Generate the final Data const Data = "RAR registration data\n" + U + "\n" + Data3 + "\n" + UID + "\n" + (Temp + Data0 + Data1 + Data2 + SZchecksum) .match(/.{1,54}/g) .join("\n");
console.log(Data);
// helper function to generate keys using SM2 algorithm function generateKeys(data) { const curve = sm2.curves.p256; const { privateKey, publicKey } = curve.keyFromSecret(Buffer.from(data)); return { privateKey, publicKey }; }
|