Skip to content

A fully open source & end-to-end encrypted note taking alternative to Evernote.

mobile: fix encryption

Ammar Ahmedd125e0f6d98f
diff --git a/apps/mobile/app/common/database/encryption.ts b/apps/mobile/app/common/database/encryption.ts
index 8d9510909..4fa892d50 100644
--- a/apps/mobile/app/common/database/encryption.ts
+++ b/apps/mobile/app/common/database/encryption.ts
@@ -339,7 +339,7 @@ export async function hash(
DatabaseLogger.log(`Hashing password: fallback: ${options?.usesFallback}`);
if (options?.usesFallback && Platform.OS !== "ios") {
- return null;
+ return "";
}
return (
@@ -350,7 +350,17 @@ export async function hash(
}
export async function generateCryptoKey(password: string, salt?: string) {
- return (await Sodium.deriveKey(password, salt)) as Promise<SerializedKey>;
+ return Sodium.deriveKey(password, salt) as Promise<SerializedKey>;
+}
+
+export async function generateCryptoKeyFallback(
+ password: string,
+ salt?: string
+): Promise<SerializedKey> {
+ return Sodium.deriveKeyFallback?.(
+ password,
+ salt as string
+ ) as Promise<SerializedKey>;
}
export function getAlgorithm(base64Variant: number) {
diff --git a/apps/mobile/app/common/database/storage.ts b/apps/mobile/app/common/database/storage.ts
index e1523b108..a9f572dba 100644
--- a/apps/mobile/app/common/database/storage.ts
+++ b/apps/mobile/app/common/database/storage.ts
@@ -27,7 +27,8 @@ import {
encryptMulti,
generateCryptoKey,
getCryptoKey,
- hash
+ hash,
+ generateCryptoKeyFallback
} from "./encryption";
import { MMKV } from "./mmkv";
@@ -146,5 +147,6 @@ export const Storage: IStorage = {
decryptMulti,
deriveCryptoKey,
generateCryptoKey,
+ generateCryptoKeyFallback,
deriveCryptoKeyFallback
};