Skip to content

Commit

Permalink
remove buffer use to support browser
Browse files Browse the repository at this point in the history
  • Loading branch information
eitanz-coti committed Sep 16, 2024
1 parent c55aebd commit 797d13a
Showing 1 changed file with 16 additions and 6 deletions.
22 changes: 16 additions & 6 deletions src/crypto_utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,15 +99,25 @@ export function recoverUserKey(privateKey: Uint8Array, encryptedKeyShare0: strin
const decryptedKeyShare0: string = decryptRSA(privateKey, encryptedKeyShare0);
const decryptedKeyShare1: string = decryptRSA(privateKey, encryptedKeyShare1);

const bufferKeyShare0 = Buffer.from(decryptedKeyShare0, 'hex'); // 'hex' because decryptRSA is returning hex-encoded string
const bufferKeyShare1 = Buffer.from(decryptedKeyShare1, 'hex');

const aesKey = Buffer.alloc(bufferKeyShare0.length);
for (let i = 0; i < bufferKeyShare0.length; i++) {
aesKey[i] = bufferKeyShare0[i] ^ bufferKeyShare1[i];
const bufferKeyShare0 = encodeKey(decryptedKeyShare0)
const bufferKeyShare1 = encodeKey(decryptedKeyShare1)
const aesKeyBytes = new Uint8Array(BLOCK_SIZE)

for (let i = 0; i < BLOCK_SIZE; i++) {
aesKeyBytes[i] = bufferKeyShare0[i] ^ bufferKeyShare1[i];
}
const aesKey: Array<string> = []

let byte = ''

for (let i = 0; i < aesKeyBytes.length; i++) {
byte = aesKeyBytes[i].toString(HEX_BASE).padStart(2, '0') // ensure that the zero byte is represented using two digits

aesKey.push(byte)
}

return aesKey.toString('hex');
return aesKey.join("")
}


Expand Down

0 comments on commit 797d13a

Please sign in to comment.