mirror of
https://github.com/kmc7468/arkvault.git
synced 2025-12-16 15:08:46 +00:00
파일 다운로드 임시 구현
This commit is contained in:
@@ -1,12 +1,12 @@
|
||||
import { callSignedPostApi } from "$lib/hooks";
|
||||
import {
|
||||
encodeToBase64,
|
||||
decodeFromBase64,
|
||||
generateDataKey,
|
||||
wrapDataKey,
|
||||
unwrapDataKey,
|
||||
encryptData,
|
||||
decryptData,
|
||||
encryptString,
|
||||
decryptString,
|
||||
digestMessage,
|
||||
signRequestBody,
|
||||
} from "$lib/modules/crypto";
|
||||
@@ -14,28 +14,18 @@ import type {
|
||||
DirectroyInfoResponse,
|
||||
DirectoryCreateRequest,
|
||||
FileUploadRequest,
|
||||
FileInfoResponse,
|
||||
} from "$lib/server/schemas";
|
||||
import type { MasterKey } from "$lib/stores";
|
||||
|
||||
export { decryptFileMetadata } from "$lib/services/file";
|
||||
|
||||
export const decryptDirectroyMetadata = async (
|
||||
metadata: NonNullable<DirectroyInfoResponse["metadata"]>,
|
||||
masterKey: CryptoKey,
|
||||
) => {
|
||||
const { dataKey } = await unwrapDataKey(metadata.dek, masterKey);
|
||||
return {
|
||||
name: new TextDecoder().decode(
|
||||
await decryptData(decodeFromBase64(metadata.name), metadata.nameIv, dataKey),
|
||||
),
|
||||
};
|
||||
};
|
||||
|
||||
export const decryptFileMetadata = async (metadata: FileInfoResponse, masterKey: CryptoKey) => {
|
||||
const { dataKey } = await unwrapDataKey(metadata.dek, masterKey);
|
||||
return {
|
||||
name: new TextDecoder().decode(
|
||||
await decryptData(decodeFromBase64(metadata.name), metadata.nameIv, dataKey),
|
||||
),
|
||||
name: await decryptString(metadata.name, metadata.nameIv, dataKey),
|
||||
};
|
||||
};
|
||||
|
||||
@@ -69,7 +59,7 @@ export const requestFileUpload = async (
|
||||
const { dataKey } = await generateDataKey();
|
||||
const fileEncrypted = await encryptData(await file.arrayBuffer(), dataKey);
|
||||
const fileEncryptedHash = await digestMessage(fileEncrypted.ciphertext);
|
||||
const nameEncrypted = await encryptData(new TextEncoder().encode(file.name), dataKey);
|
||||
const nameEncrypted = await encryptString(file.name, dataKey);
|
||||
|
||||
const form = new FormData();
|
||||
form.set(
|
||||
@@ -81,7 +71,7 @@ export const requestFileUpload = async (
|
||||
dek: await wrapDataKey(dataKey, masterKey.key),
|
||||
contentHash: encodeToBase64(fileEncryptedHash),
|
||||
contentIv: fileEncrypted.iv,
|
||||
name: encodeToBase64(nameEncrypted.ciphertext),
|
||||
name: nameEncrypted.ciphertext,
|
||||
nameIv: nameEncrypted.iv,
|
||||
},
|
||||
signKey,
|
||||
|
||||
Reference in New Issue
Block a user