[feat] risupreset file
This commit is contained in:
@@ -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
|
||||
}
|
||||
Reference in New Issue
Block a user