Skip to content

armgit / ente

Public Imported from GitHub
0

πŸ’š End-to-end encrypted cloud for everything.

We need both

Manav Rathid1b7177a53c9
diff --git a/web/packages/base/crypto/ente-impl.ts b/web/packages/base/crypto/ente-impl.ts
index 71ecc88b7a..305cee31e7 100644
--- a/web/packages/base/crypto/ente-impl.ts
+++ b/web/packages/base/crypto/ente-impl.ts
@@ -31,6 +31,8 @@ export const _encryptMetadataJSON = ({ jsonValue, keyB64 }: EncryptJSON) =>
keyB64,
});
+export const _decryptBox = libsodium.decryptBox2;
+
export const _decryptBoxB64 = libsodium.decryptBoxB64;
export const _decryptAssociatedData = libsodium.decryptBlob;
diff --git a/web/packages/base/crypto/ente.ts b/web/packages/base/crypto/ente.ts
index afd7ceb606..01682c2ec5 100644
--- a/web/packages/base/crypto/ente.ts
+++ b/web/packages/base/crypto/ente.ts
@@ -142,8 +142,15 @@ export const encryptMetadataJSON = async (r: EncryptJSON) =>
: sharedCryptoWorker().then((w) => w.encryptMetadataJSON(r));
/**
- * Decrypt a box encrypted using {@link encryptBoxB64}, and return the result as
- * a base64 string.
+ * Decrypt a box encrypted using {@link encryptBoxB64}.
+ */
+export const decryptBox = (box: EncryptedBox2, key: BytesOrB64) =>
+ inWorker()
+ ? ei._decryptBox(box, key)
+ : sharedCryptoWorker().then((w) => w.decryptBox(box, key));
+
+/**
+ * Variant of {@link decryptBoxlink} that returns the result as a base64 string.
*/
export const decryptBoxB64 = (box: EncryptedBox2, key: BytesOrB64) =>
inWorker()
diff --git a/web/packages/base/crypto/libsodium.ts b/web/packages/base/crypto/libsodium.ts
index 2937d1a7ba..bb19f53f6e 100644
--- a/web/packages/base/crypto/libsodium.ts
+++ b/web/packages/base/crypto/libsodium.ts
@@ -380,12 +380,7 @@ export const decryptBox = async ({
/**
* Decrypt the result of {@link encryptBoxB64}.
*/
-export const decryptBoxB64 = (
- box: EncryptedBox2,
- key: BytesOrB64,
-): Promise<string> => _decryptBox(box, key).then(toB64);
-
-export const _decryptBox = async (
+export const decryptBox2 = async (
{ encryptedData, nonce }: EncryptedBox2,
key: BytesOrB64,
): Promise<Uint8Array> => {
@@ -397,6 +392,14 @@ export const _decryptBox = async (
);
};
+/**
+ * Variant of {@link decryptBox} that returns the data as a base64 string.
+ */
+export const decryptBoxB64 = (
+ box: EncryptedBox2,
+ key: BytesOrB64,
+): Promise<string> => decryptBox2(box, key).then(toB64);
+
/**
* Decrypt the result of {@link encryptBlob}.
*/
diff --git a/web/packages/base/crypto/worker.ts b/web/packages/base/crypto/worker.ts
index 72ae1fb332..13e36c546d 100644
--- a/web/packages/base/crypto/worker.ts
+++ b/web/packages/base/crypto/worker.ts
@@ -15,6 +15,7 @@ export class CryptoWorker {
encryptBoxB64 = ei._encryptBoxB64;
encryptThumbnail = ei._encryptThumbnail;
encryptMetadataJSON = ei._encryptMetadataJSON;
+ decryptBox = ei._decryptBox;
decryptBoxB64 = ei._decryptBoxB64;
decryptThumbnail = ei._decryptThumbnail;
decryptAssociatedDataB64 = ei._decryptAssociatedDataB64;