소스 검색

feat: 修改密钥以及密钥使用方式

BaiLuoYan 3 달 전
부모
커밋
fb247691cf
2개의 변경된 파일8개의 추가작업 그리고 5개의 파일을 삭제
  1. 5 3
      src/config/request/encryptionInterceptors.ts
  2. 3 2
      src/utils/requestCrypto.ts

+ 5 - 3
src/config/request/encryptionInterceptors.ts

@@ -7,7 +7,7 @@ import {
     decryptResponsePayload,
     encryptRequestPayload,
 } from '@/utils/requestCrypto';
-import { bytesToString } from '@/utils/bytesUtils';
+import { bytesToString, stringToBytes } from '@/utils/bytesUtils';
 import { currentUnixTimestamp } from '@/utils/timeUtils';
 import {
     IRequestInterceptorAxios,
@@ -59,7 +59,8 @@ export const requestEncryptionInterceptor: IRequestInterceptorAxios = async (con
         config.headers['Content-Type'] = 'application/octet-stream';
 
         // 加密请求体
-        const keyBytes = bytesBase64decode(encryptionKey);
+        // const keyBytes = bytesBase64decode(encryptionKey);
+        const keyBytes = stringToBytes(encryptionKey);
         const dataBytes = new TextEncoder().encode(JSON.stringify(config.data));
         const encrypted = await encryptRequestPayload(
             dataBytes,
@@ -102,7 +103,8 @@ export const responseDecryptionInterceptor: IResponseInterceptor = async (respon
         const encryptedBytes = new Uint8Array(
             raw instanceof ArrayBuffer ? raw : (raw as ArrayBuffer)
         );
-        const keyBytes = bytesBase64decode(encryptionKey);
+        // const keyBytes = bytesBase64decode(encryptionKey);
+        const keyBytes = stringToBytes(encryptionKey);
         const decrypted = await decryptResponsePayload(
             encryptedBytes,
             keyBytes,

+ 3 - 2
src/utils/requestCrypto.ts

@@ -1,5 +1,5 @@
 import { aesCbcDecryptBytes, aesCbcEncryptBytes, bytesBase64decode } from '@/utils/crypto';
-import { bytesToNumber, numberToBytesAt, Endian, bytesToString } from '@/utils/bytesUtils';
+import { bytesToNumber, numberToBytesAt, Endian, bytesToString, stringToBytes } from '@/utils/bytesUtils';
 
 import globalConfig from '@/config';
 
@@ -94,7 +94,8 @@ export async function decryptResponsePayload(
 }
 
 export async function decryptUrlParams<T = any>(params: string): Promise<T | null> {
-    const key = bytesBase64decode(globalConfig.security.requestEncryptionKey);
+    // const key = bytesBase64decode(globalConfig.security.requestEncryptionKey);
+    const key = stringToBytes(globalConfig.security.requestEncryptionKey);
     const dataBytes = bytesBase64decode(params);
     const compressMethod = globalConfig.security.compressMethod;
     try {