tiefen_space_h5/utils/crypto.js

60 lines
1.4 KiB
JavaScript
Raw Permalink Normal View History

2024-07-02 15:09:48 +08:00
export function cryptoPassword(password) {
const Salt = "6%dkszcU*&lk@#$T#(lknkj.359";
const encryptedPassword = calcEncryptedPassword(password);
return encryptedPassword;
function calcEncryptedPassword(password) {
if (!password || password.length <= 7) {
2024-08-05 18:59:30 +08:00
// console.log("Invalid input");
2024-07-02 15:09:48 +08:00
return;
}
const payload = password + Salt;
const len = payload.length;
const a1 = payload.substring(0, 3);
const a2 = payload.substring(3, len - 3);
const a3 = payload.substring(len - 3);
2024-07-22 16:41:33 +08:00
const crypto = require("crypto");
2024-07-02 15:09:48 +08:00
const md5Hash = crypto.createHash("md5");
md5Hash.update(a1 + a3 + a2);
const encryptedPassword = md5Hash.digest("hex");
return encryptedPassword;
}
}
export function generateSignature(body) {
const Salt = "6%dkszcU*&lk@#$T#(lknkj.359";
const jsonBody = JSON.stringify(body);
const signature = calcSignature(jsonBody);
return signature;
function calcSignature(s) {
if (!s || s.length <= 20) {
2024-08-05 18:59:30 +08:00
// console.log("Invalid input");
2024-07-02 15:09:48 +08:00
return;
}
const payload = s + Salt;
const len = payload.length;
const a1 = payload.substring(0, 10);
const a2 = payload.substring(10, len - 10);
const a3 = payload.substring(len - 10);
2024-07-22 16:41:33 +08:00
const crypto = require("crypto");
2024-07-02 15:09:48 +08:00
const md5Hash = crypto.createHash("md5");
md5Hash.update(a1 + a3 + a2);
const signature = md5Hash.digest("hex");
return signature;
}
}