mirror of
https://github.com/iLay1678/i-tools.git
synced 2025-07-03 18:52:17 +08:00
update
This commit is contained in:
parent
a2deaf2f35
commit
df2b8cf006
@ -1,14 +1,15 @@
|
|||||||
|
import pkg from 'crypto-js';
|
||||||
|
const { AES, enc, mode, pad, MD5 } = pkg;
|
||||||
|
|
||||||
import crypto from "crypto-js";
|
|
||||||
const decrypt = function (ciphertext: string, iv: string, t: number): string {
|
const decrypt = function (ciphertext: string, iv: string, t: number): string {
|
||||||
try {
|
try {
|
||||||
const key = generateKey(t);
|
const key = generateKey(t);
|
||||||
const decrypted = crypto.AES.decrypt(ciphertext, crypto.enc.Utf8.parse(key), {
|
const decrypted = AES.decrypt(ciphertext, enc.Utf8.parse(key), {
|
||||||
iv: crypto.enc.Hex.parse(iv),
|
iv: enc.Hex.parse(iv),
|
||||||
mode: crypto.mode.CBC,
|
mode:mode.CBC,
|
||||||
padding: crypto.pad.Pkcs7
|
padding: pad.Pkcs7
|
||||||
});
|
});
|
||||||
const dec = crypto.enc.Utf8.stringify(decrypted).toString();
|
const dec = enc.Utf8.stringify(decrypted).toString();
|
||||||
return dec;
|
return dec;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error("Decryption failed", error);
|
console.error("Decryption failed", error);
|
||||||
@ -59,7 +60,7 @@ const generateKey = function (t: number): string {
|
|||||||
|
|
||||||
const keyArray = concatenatedParams.split("");
|
const keyArray = concatenatedParams.split("");
|
||||||
const hashedKey = h(keyArray, t);
|
const hashedKey = h(keyArray, t);
|
||||||
return crypto.MD5(hashedKey).toString(crypto.enc.Hex);
|
return MD5(hashedKey).toString(enc.Hex);
|
||||||
};
|
};
|
||||||
|
|
||||||
export { decrypt, getParams };
|
export { decrypt, getParams };
|
||||||
|
Loading…
x
Reference in New Issue
Block a user