diff options
Diffstat (limited to 'packages/meshbay-hub/src/meshbay_hub/static/crypto.js')
| -rw-r--r-- | packages/meshbay-hub/src/meshbay_hub/static/crypto.js | 11 |
1 files changed, 9 insertions, 2 deletions
diff --git a/packages/meshbay-hub/src/meshbay_hub/static/crypto.js b/packages/meshbay-hub/src/meshbay_hub/static/crypto.js index 7862283..ee442fb 100644 --- a/packages/meshbay-hub/src/meshbay_hub/static/crypto.js +++ b/packages/meshbay-hub/src/meshbay_hub/static/crypto.js @@ -136,7 +136,7 @@ function b64decode(b64) { function hexToBytes(hex) { const bytes = new Uint8Array(hex.length / 2); for (let i = 0; i < hex.length; i += 2) - bytes[i / 2] = parseInt(hex.substring(i, 2), 16); + bytes[i / 2] = parseInt(hex.substring(i, i + 2), 16); return bytes; } @@ -151,5 +151,12 @@ function concatBuffers(arrays) { return result; } +async function decryptChunkBin(gek, fileHashHex, chunkIndex, nonce, ct) { + const chunkKey = await deriveChunkKey(gek, fileHashHex, chunkIndex); + const plaintext = await crypto.subtle.decrypt( + { name: 'AES-GCM', iv: nonce }, chunkKey, ct); + return new Uint8Array(plaintext); +} + // Export for use in app.js -window.MeshBayCrypto = { importGEK, deriveChunkKey, decryptChunk, decryptFile }; +window.MeshBayCrypto = { importGEK, deriveChunkKey, decryptChunk, decryptChunkBin, decryptFile }; |