Page MenuHomePhabricator

D7761.diff
No OneTemporary

D7761.diff

diff --git a/native/media/encryption-utils.js b/native/media/encryption-utils.js
--- a/native/media/encryption-utils.js
+++ b/native/media/encryption-utils.js
@@ -396,4 +396,26 @@
};
}
-export { encryptMedia, decryptMedia };
+function encryptBase64(
+ base64: string,
+ keyBytes?: Uint8Array,
+): { +base64: string, +keyHex: string } {
+ const rawData = commUtilsModule.base64DecodeBuffer(base64);
+ const aesKey = keyBytes ?? AES.generateKey();
+ const encrypted = AES.encrypt(aesKey, new Uint8Array(rawData));
+ return {
+ base64: commUtilsModule.base64EncodeBuffer(encrypted.buffer),
+ keyHex: uintArrayToHexString(aesKey),
+ };
+}
+
+function decryptBase64(encrypted: string, keyHex: string): string {
+ const encryptedData = commUtilsModule.base64DecodeBuffer(encrypted);
+ const decryptedData = AES.decrypt(
+ hexToUintArray(keyHex),
+ new Uint8Array(encryptedData),
+ );
+ return commUtilsModule.base64EncodeBuffer(decryptedData.buffer);
+}
+
+export { encryptMedia, decryptMedia, encryptBase64, decryptBase64 };

File Metadata

Mime Type
text/plain
Expires
Sat, Nov 30, 7:27 PM (21 h, 54 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2602119
Default Alt Text
D7761.diff (1 KB)

Event Timeline