From e221d61dce64dbd4b339dc3c6f85a55fcc2fabe0 Mon Sep 17 00:00:00 2001 From: Suzu008 Date: Sat, 11 Oct 2025 20:16:36 +0800 Subject: [PATCH] remove mannually padding remoove process( which is already done in decrypt process --- ts/cryptioUploadImage.ts | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/ts/cryptioUploadImage.ts b/ts/cryptioUploadImage.ts index 94da90b..23917aa 100644 --- a/ts/cryptioUploadImage.ts +++ b/ts/cryptioUploadImage.ts @@ -229,16 +229,11 @@ async function exchangeKeys(): Promise { encryptedData ); - // 4. 去除PKCS7 padding - const decryptedArray = new Uint8Array(decryptedBuffer); - const paddingLength = decryptedArray[decryptedArray.length - 1]; - const unpaddedData = decryptedArray.slice(0, -paddingLength); - - // 5. 解析JSON - const decryptedText = new TextDecoder().decode(unpaddedData); + // 4. 解析JSON + const decryptedText = new TextDecoder().decode(decryptedBuffer); const serverKeys = JSON.parse(decryptedText); - // 保存到localStorage + // 5. 保存到localStorage localStorage.setItem(SERVER_KEYS_STORAGE_KEY, JSON.stringify(serverKeys)); return serverKeys; @@ -388,7 +383,7 @@ async function uploadEncryptedImage(file: File): Promise { // 创建FormData const formData = new FormData(); - const encryptedBlob = new Blob([encryptedData], { + const encryptedBlob = new Blob([new Uint8Array(encryptedData)], { type: "application/octet-stream", }); formData.append("image", encryptedBlob, file.name); @@ -426,7 +421,7 @@ async function loadEncryptedImageForPreview(filename: string): Promise { const decryptedData = await decryptFile(encryptedData); // 转换为Blob URL - const blob = new Blob([decryptedData]); + const blob = new Blob([new Uint8Array(decryptedData)]); return URL.createObjectURL(blob); }