|
1 | 1 | import { useCallback, useMemo, useState } from 'react' |
2 | | -import { fromHex, toHex } from '@/lib/hex' |
3 | 2 | import { useMe } from '@/components/me' |
4 | 3 | import { useIndexedDB } from '@/components/use-indexeddb' |
5 | 4 | import { useShowModal } from '@/components/modal' |
@@ -307,7 +306,7 @@ export async function deriveKey (passphrase, salt) { |
307 | 306 | ) |
308 | 307 |
|
309 | 308 | const rawKey = await window.crypto.subtle.exportKey('raw', key) |
310 | | - const hash = toHex(await window.crypto.subtle.digest('SHA-256', rawKey)) |
| 309 | + const hash = Buffer.from(await window.crypto.subtle.digest('SHA-256', rawKey)).toString('hex') |
311 | 310 | const unextractableKey = await window.crypto.subtle.importKey( |
312 | 311 | 'raw', |
313 | 312 | rawKey, |
@@ -338,19 +337,19 @@ async function _encrypt ({ key, hash }, value) { |
338 | 337 | ) |
339 | 338 | return { |
340 | 339 | keyHash: hash, |
341 | | - iv: toHex(iv.buffer), |
342 | | - value: toHex(encrypted) |
| 340 | + iv: Buffer.from(iv).toString('hex'), |
| 341 | + value: Buffer.from(encrypted).toString('hex') |
343 | 342 | } |
344 | 343 | } |
345 | 344 |
|
346 | 345 | async function _decrypt (key, { iv, value }) { |
347 | 346 | const decrypted = await window.crypto.subtle.decrypt( |
348 | 347 | { |
349 | 348 | name: 'AES-GCM', |
350 | | - iv: fromHex(iv) |
| 349 | + iv: Buffer.from(iv, 'hex') |
351 | 350 | }, |
352 | 351 | key, |
353 | | - fromHex(value) |
| 352 | + Buffer.from(value, 'hex') |
354 | 353 | ) |
355 | 354 | const decoded = new TextDecoder().decode(decrypted) |
356 | 355 | return JSON.parse(decoded) |
|
0 commit comments