|
|
@@ -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;
|
|
|
};
|
|
|
|