full site update

This commit is contained in:
2025-07-24 18:46:24 +02:00
parent bfe2b90d8d
commit 37a6e0ab31
6912 changed files with 540482 additions and 361712 deletions

View File

@@ -1,4 +1,5 @@
import { decodeBase64, decodeHex, encodeBase64, encodeHexUpperCase } from "@oslojs/encoding";
import { ALGORITHMS } from "./csp/config.js";
const ALGORITHM = "AES-GCM";
async function createKey() {
const key = await crypto.subtle.generateKey(
@@ -27,10 +28,6 @@ async function getEnvironmentKey() {
const encodedKey = getEncodedEnvironmentKey();
return decodeKey(encodedKey);
}
async function importKey(bytes) {
const key = await crypto.subtle.importKey("raw", bytes, ALGORITHM, true, ["encrypt", "decrypt"]);
return key;
}
async function encodeKey(key) {
const exported = await crypto.subtle.exportKey("raw", key);
const encodedKey = encodeBase64(new Uint8Array(exported));
@@ -70,14 +67,18 @@ async function decryptString(key, encoded) {
const decryptedString = decoder.decode(decryptedBuffer);
return decryptedString;
}
async function generateCspDigest(data, algorithm) {
const hashBuffer = await crypto.subtle.digest(algorithm, encoder.encode(data));
const hash = encodeBase64(new Uint8Array(hashBuffer));
return `${ALGORITHMS[algorithm]}${hash}`;
}
export {
createKey,
decodeKey,
decryptString,
encodeKey,
encryptString,
getEncodedEnvironmentKey,
generateCspDigest,
getEnvironmentKey,
hasEnvironmentKey,
importKey
hasEnvironmentKey
};