mirror of
https://github.com/kmc7468/arkvault.git
synced 2025-12-16 06:58:46 +00:00
파일 다운로드 임시 구현
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import { encodeToBase64, decodeFromBase64 } from "./util";
|
||||
import { encodeString, decodeString, encodeToBase64, decodeFromBase64 } from "./util";
|
||||
|
||||
export const generateMasterKey = async () => {
|
||||
return {
|
||||
@@ -81,3 +81,12 @@ export const decryptData = async (ciphertext: BufferSource, iv: string, dataKey:
|
||||
ciphertext,
|
||||
);
|
||||
};
|
||||
|
||||
export const encryptString = async (plaintext: string, dataKey: CryptoKey) => {
|
||||
const { ciphertext, iv } = await encryptData(encodeString(plaintext), dataKey);
|
||||
return { ciphertext: encodeToBase64(ciphertext), iv };
|
||||
};
|
||||
|
||||
export const decryptString = async (ciphertext: string, iv: string, dataKey: CryptoKey) => {
|
||||
return decodeString(await decryptData(decodeFromBase64(ciphertext), iv, dataKey));
|
||||
};
|
||||
|
||||
@@ -1,3 +1,14 @@
|
||||
const textEncoder = new TextEncoder();
|
||||
const textDecoder = new TextDecoder();
|
||||
|
||||
export const encodeString = (data: string) => {
|
||||
return textEncoder.encode(data);
|
||||
};
|
||||
|
||||
export const decodeString = (data: ArrayBuffer) => {
|
||||
return textDecoder.decode(data);
|
||||
};
|
||||
|
||||
export const encodeToBase64 = (data: ArrayBuffer) => {
|
||||
return btoa(String.fromCharCode(...new Uint8Array(data)));
|
||||
};
|
||||
|
||||
10
src/lib/services/file.ts
Normal file
10
src/lib/services/file.ts
Normal file
@@ -0,0 +1,10 @@
|
||||
import { unwrapDataKey, decryptString } from "$lib/modules/crypto";
|
||||
import type { FileInfoResponse } from "$lib/server/schemas";
|
||||
|
||||
export const decryptFileMetadata = async (metadata: FileInfoResponse, masterKey: CryptoKey) => {
|
||||
const { dataKey } = await unwrapDataKey(metadata.dek, masterKey);
|
||||
return {
|
||||
dataKey,
|
||||
name: await decryptString(metadata.name, metadata.nameIv, dataKey),
|
||||
};
|
||||
};
|
||||
Reference in New Issue
Block a user