|

9精币
const CryptoJS = require ( const pako = require ( /** * 十六进制字符串转Uint8Array * [url=home.php?mod=space&uid=275307]@param[/url] {string} hexStr - 十六进制字符串 * @returns {Uint8Array} 转换后的字节数组 */ function hexToUint8Array (hexStr) { // 移除可能的空格 hexStr = hexStr.replace (/\s/g, if (hexStr.length % 2 !== 0) { throw new Error ( } const bytes = new Uint8Array (hexStr.length / 2); for (let i = 0; i < bytes.length; i++) { const twoChars = hexStr.substr (i * 2, 2); bytes[i] = parseInt (twoChars, 16); } return bytes; } /** * Uint8Array转WordArray * @param {Uint8Array} uint8Array - 字节数组 * @returns {CryptoJS.lib.WordArray} CryptoJS的WordArray */ function uint8ArrayToWordArray (uint8Array) { const words = []; for (let i = 0; i < uint8Array.length; i++) { words[i >>> 2] |= (uint8Array[i] & 0xff) << (24 - (i % 4) * 8); } return CryptoJS.lib.WordArray.create (words, uint8Array.length); } /** * WordArray转Uint8Array * @param {CryptoJS.lib.WordArray} wordArray - CryptoJS的WordArray * @returns {Uint8Array} 字节数组 */ function wordArrayToUint8Array (wordArray) { const bytes = new Uint8Array (wordArray.sigBytes); for (let i = 0; i < bytes.length; i++) { bytes[i] = (wordArray.words[i >>> 2] >>> (24 - (i % 4) * 8)) & 0xff; } return bytes; } /** * 解密十六进制密文 * @param {string} hexCiphertext - 十六进制密文 * @param {CryptoJS.lib.WordArray} key - 解密密钥 * @returns {string} 解密后的内容 */ function decryptHex (hexCiphertext, key) { try { // 1. 十六进制转字节数组 const cipherBytes = hexToUint8Array (hexCiphertext); console.log ( // 2. 字节数组转WordArray const cipherWordArray = uint8ArrayToWordArray (cipherBytes); // 3. AES-CBC解密(假设使用与之前相同的参数) const decryptedWordArray = CryptoJS.AES.decrypt ( { ciphertext: cipherWordArray }, key, { iv: key, // IV=密钥(与之前加密逻辑一致) mode: CryptoJS.mode.CBC, padding: CryptoJS.pad.Pkcs7 } ); // 4. 解密结果转字节数组 const decryptedBytes = wordArrayToUint8Array (decryptedWordArray); console.log ( console.log ( // 5. 尝试gzip解压 let resultBytes; try { resultBytes = pako.ungzip (decryptedBytes); console.log ( } catch (e) { console.log ( resultBytes = decryptedBytes; } // 6. 转字符串 return new TextDecoder ( } catch (error) { console.error ( return null; } } // ------------------------------ // 配置参数 // ------------------------------ const config = { // 十六进制密文 hexCiphertext: "215C133DFC2013CA85D18C62D075E3A20BA605FD4285D33A3EE3DEC7E2F1CCCD1099FC108D5129CE5D7DC26288C555E07F4429C95A3E28910CA9E77D064B69FCC4E284CE08C5A9BA2F8D92623A1EB2F79DCE7E09285989ACBBAA2474C559E2A5A9906F8AA774A0F56B32A5163F79EE9AF0A26DCC8040409751A3FF5012F13BE3DC382768C96E404D92E7C5026D160B420F6CDA470DA90B84E291B5BB7F81D16454A0497B10E3A1BDA47E1B44D71BD9AA8788F3CE0512AE5F3B63F38AFB1D80A69863C06FF549D5960508FC00261A105B576555163D5175684D3C89D24A7DFD12571353806E8E202B2F1D4E2EDAA6EDC3DBB8B012F56A16C6BC233F2C9746EBAE34B8E10255719A69D26F374DEADFFFBE120E3460B1FDB886C246EC0507A53FC34715F6B9B09C66E2E4289A92ACAF131CEB7CD24E364136D92750D18D6CB08AA18A4ED5842F27768013C91ED6CBC500563F236CFC4B5B0735F679949C3ACFB1670333271DE981C67B26A779823834694047254FD74C1C4271FA3666544EB93ADF5DA2729F421D0797CECFDF48DE588E6B0C6F70EE1CD1DD549646F96BBB7B34D8EB4CE5E43FE6DE4B528CD3655C6F1FD0D9763C55D0DD986D6A135F61627645DBF566A3A51E207978AB6F7958E35E58FD57BB7C8A9D0ECF00733822B2E05220EE7F1FF5F7D53921C08170B57DCD0456FF4B2387F39ACAC5110A59AB947F3DA13FFE3D72FC93BB3A59F04C008F707392684C796D960282ED2CC2141635304524869FE405BE32A752FEC50D7D90979E4F664CA6AA03125CCAD9B657211BEADDCB611CA0C47A5D08DC52C15E3FE31AB63F25904CFB93BE72FAA4834EC1871B8E509872E6CF1D8C8AD0A75A28534A662930B311DFC3D9F5C5F8844FF46723EEA55890895586ABCBBB3F90DAF1C10CDE1FD0655EFE858FA400B92095A46383DA89EAE583ED1486AB3554A0731C5B54C403EB81",
// 请替换为实际加密密钥(示例为之前的密钥格式) key: CryptoJS.lib.WordArray.create ( [1162098497, 1093678658, 1144534578, 943863093], // 替换为实际密钥的words数组 16 // 密钥长度(16字节=128位,32字节=256位) ) }; // ------------------------------ // 执行解密ac // ------------------------------ const result = decryptHex (config.hexCiphertext, config.key); if (result) { console.log ( console.log (result); // 尝试解析为JSON try { const jsonResult = JSON.parse (result); console.log ( console.log (JSON.stringify (jsonResult, null, 2)); } catch (e) { console.log ( } } Visual Studio Code
|
|