[feat] risupreset file

This commit is contained in:
kwaroran
2023-11-22 23:31:56 +09:00
parent 900989487b
commit 2cdaf03f42
2 changed files with 83 additions and 6 deletions

View File

@@ -309,4 +309,54 @@ export function getAuthorNoteDefaultText(){
}
return ''
}
export async function encryptBuffer(data:Uint8Array, keys:string){
// hash the key to get a fixed length key value
const keyArray = await window.crypto.subtle.digest("SHA-256", new TextEncoder().encode(keys))
const key = await window.crypto.subtle.importKey(
"raw",
keyArray,
"AES-GCM",
false,
["encrypt", "decrypt"]
)
// use web crypto api to encrypt the data
const result = await window.crypto.subtle.encrypt(
{
name: "AES-GCM",
iv: new Uint8Array(12),
},
key,
data
)
return result
}
export async function decryptBuffer(data:Uint8Array, keys:string){
// hash the key to get a fixed length key value
const keyArray = await window.crypto.subtle.digest("SHA-256", new TextEncoder().encode(keys))
const key = await window.crypto.subtle.importKey(
"raw",
keyArray,
"AES-GCM",
false,
["encrypt", "decrypt"]
)
// use web crypto api to encrypt the data
const result = await window.crypto.subtle.decrypt(
{
name: "AES-GCM",
iv: new Uint8Array(12),
},
key,
data
)
return result
}