From a99080fb74ffd875d9d975ef08d45add1ae0112a Mon Sep 17 00:00:00 2001 From: ansuz Date: Mon, 22 May 2017 12:31:00 +0200 Subject: [PATCH] push the rest of the code --- www/file/file-crypto.js | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/www/file/file-crypto.js b/www/file/file-crypto.js index c7bd74ea3..a36a3fc19 100644 --- a/www/file/file-crypto.js +++ b/www/file/file-crypto.js @@ -61,6 +61,19 @@ define([ return new Blob(chunks); }; + var decryptMetadata = function (u8, key) { + var prefix = u8.subarray(0, 2); + var metadataLength = decodePrefix(prefix); + + var metaBox = new Uint8Array(u8.subarray(2, 2 + metadataLength)); + var metaChunk = Nacl.secretbox.open(metaBox, createNonce(), key); + + try { + return JSON.parse(Nacl.util.encodeUTF8(metaChunk)); + } + catch (e) { return null; } + }; + var decrypt = function (u8, key, done, progress) { var MAX = u8.length; var _progress = function (offset) { @@ -198,5 +211,6 @@ define([ encrypt: encrypt, joinChunks: joinChunks, computeEncryptedSize: computeEncryptedSize, + decryptMetadata: decryptMetadata, }; });