Преглед на файлове

Merge branch 'master' of http://47.101.159.18:3000/Muchinfo/MTP2.0_WEB

huangbin преди 4 години
родител
ревизия
e128ff4554
променени са 1 файла, в които са добавени 15 реда и са изтрити 6 реда
  1. 15 6
      src/utils/websocket/crypto/index.ts

+ 15 - 6
src/utils/websocket/crypto/index.ts

@@ -7,7 +7,7 @@ const macKeyLeft: CryptoJS.lib.WordArray = CryptoJS.enc.Hex.parse('B0FB83E39A5EB
 /** MAC检验码右8字节 */
 const macKeyRight: CryptoJS.lib.WordArray = CryptoJS.enc.Hex.parse('BE471362A58393FF');
 /** Phone AES密钥 */
-const phoneaeskey: CryptoJS.lib.WordArray = CryptoJS.enc.Utf8.parse('0d299ce2d4105282f7471074cb0f9f9d');
+const phoneaeskey = '0d299ce2d4105282f7471074cb0f9f9d';
 /** MAC检验向量 */
 const iv = new Uint8Array([0xd9, 0x51, 0xdb, 0xe0, 0x37, 0xc8, 0x23, 0x25]);
 
@@ -159,14 +159,23 @@ export const decrypt50 = (encryptData: Uint8Array, size: number): Uint8Array | n
  * @param size 明文长度
  */
 export const decryptAES = (value: string): string | undefined => {
-    const uint8array = new TextEncoder().encode(value)
+    const ciphertext = Uint8Array.from(Buffer.from(value, 'hex'));
+    const key = Uint8Array.from(Buffer.from(phoneaeskey, 'hex'));
+
     const cipherParams = CryptoJS.lib.CipherParams.create({
-        ciphertext: uint8ArrayToWordArray(uint8array),
+        ciphertext: uint8ArrayToWordArray(ciphertext),
     });
-    const decrytped = CryptoJS.AES.decrypt(cipherParams, phoneaeskey, aesOption);
 
-    const result = wordArrayToUint8Array(decrytped);
+    const decrytped = CryptoJS.AES.decrypt(cipherParams, uint8ArrayToWordArray(key), aesOption);
+
+    let h = wordArrayToUint8Array(decrytped);
+    const index = h.findIndex(item => item == 4);
+    if (index !== -1) {
+        h = h.subarray(0, index-1);
+    }
+
+    const result = new TextDecoder().decode(h);
 
-    return new TextDecoder().decode(result);
+    return result;
 };