salt based on roomId for encrypted room messages

This commit is contained in:
AtHeartEngineer
2023-11-13 23:28:54 +03:00
parent 09e10886e0
commit bd96c42f5b
2 changed files with 3 additions and 3 deletions

View File

@@ -39,12 +39,12 @@ function getSalt(): Uint8Array {
* @param {string} password - The password to derive the encryption key from.
* @returns {Promise<CryptoKey>} - Returns the derived key as a Promise.
*/
export async function deriveKey(password: string): Promise<CryptoKey> {
export async function deriveKey(password: string, saltString?: string): Promise<CryptoKey> {
// TextEncoder will be used for converting strings to byte arrays
const textEncoder = new TextEncoder();
// Salt for PBKDF2 stored in local storage
const salt = getSalt();
const salt = saltString ? textEncoder.encode(saltString) : getSalt();
// Importing the password as a cryptographic key
const passwordKey = await window.crypto.subtle.importKey(

View File

@@ -69,7 +69,7 @@
throw new Error('ROOM IS ENCRYPTED BUT NO PASSWORD WAS FOUND');
}
if (!$roomKeyStore[roomId]) {
key = await deriveKey($roomPassStore[roomId].password);
key = await deriveKey($roomPassStore[roomId].password, roomId);
$roomKeyStore[roomId] = key;
} else {
key = $roomKeyStore[roomId];