Changeset View
Changeset View
Standalone View
Standalone View
web/database/utils/worker-crypto-utils.js
// @flow | // @flow | ||||
const ENCRYPTION_ALGORITHM = 'AES-GCM'; | const ENCRYPTION_ALGORITHM = 'AES-GCM'; | ||||
type EncryptedData = { | type EncryptedData = { | ||||
+iv: BufferSource, | +iv: BufferSource, | ||||
+ciphertext: Uint8Array, | +ciphertext: Uint8Array, | ||||
}; | }; | ||||
function generateDatabaseCryptoKey(): Promise<CryptoKey> { | function generateDatabaseCryptoKey({ | ||||
extractable, | |||||
}: { | |||||
+extractable: boolean, | |||||
}): Promise<CryptoKey> { | |||||
return crypto.subtle.generateKey( | return crypto.subtle.generateKey( | ||||
{ | { | ||||
name: ENCRYPTION_ALGORITHM, | name: ENCRYPTION_ALGORITHM, | ||||
length: 256, | length: 256, | ||||
}, | }, | ||||
false, | extractable, | ||||
['encrypt', 'decrypt'], | ['encrypt', 'decrypt'], | ||||
); | ); | ||||
} | } | ||||
function generateIV(): BufferSource { | function generateIV(): BufferSource { | ||||
return crypto.getRandomValues(new Uint8Array(12)); | return crypto.getRandomValues(new Uint8Array(12)); | ||||
} | } | ||||
Show All 36 Lines |