INNER CODE UNIT · TypeScript

loadDecryptionKey

backbone-hq/minibone · src/core.ts:51

export const loadDecryptionKey = async (keyData: Uint8Array): Promise<CryptoKey> => {
  return await crypto.subtle.importKey('raw', keyData, ENCRYPTION_ALGORITHM, false, ['decrypt'])
}

export const encryptData = async (
  data: Uint8Array,
  key: CryptoKey,
  associatedData?: Uint8Array
): Promise<[Uint8Array, Uint8Array]> => {
  const iv = crypto.getRandomValues(new Uint8Array(12))
  const buffer = await crypto.subtle.encrypt({ ...ENCRYPTION_ALGORITHM, iv, additionalData: associatedData }, key, data)
  return [iv, new Uint8Array(buffer)]
}

export const decryptData = async (
  iv: Uint8Array,
  ciphertext: Uint8Array,
  key: CryptoKey,

View source record →

📰 Research Paper
Loading…
⏳ Fetching content…