diff --git a/src/routes/journals/ae_comp__journal_entry_obj_id_view.svelte b/src/routes/journals/ae_comp__journal_entry_obj_id_view.svelte index bdb30b13..de274fd4 100644 --- a/src/routes/journals/ae_comp__journal_entry_obj_id_view.svelte +++ b/src/routes/journals/ae_comp__journal_entry_obj_id_view.svelte @@ -472,131 +472,9 @@ goto(`/journals/${tmp_entry_obj?.journal_id}`); } - // async function generate_iv() { - // const data = new Uint8Array(16); - // crypto.getRandomValues(data); - // return data; - // } - - // async function encrypt_content(content, keyData) { - // const iv = await generate_iv(); - // const keyBytes = await crypto.subtle.digest('SHA-256', new TextEncoder().encode(keyData)); - // const key = await crypto.subtle.importKey('raw', keyBytes, { name: 'AES-CBC' }, false, ['encrypt']); - // const encodedContent = await crypto.subtle.encrypt({ name: 'AES-CBC', iv }, key, new TextEncoder().encode(content)); - // const base64 = btoa(String.fromCharCode(...new Uint8Array(encodedContent))); - // console.log('Base64 Encoded Content:', base64); - // return { base64, iv }; - // } - - // async function decrypt_content(base64Content, iv, keyData) { - // const keyBytes = await crypto.subtle.digest('SHA-256', new TextEncoder().encode(keyData)); - // const key = await crypto.subtle.importKey('raw', keyBytes, { name: 'AES-CBC' }, false, ['decrypt']); - // const encryptedContent = Uint8Array.from(atob(base64Content), c => c.charCodeAt(0)); - // const decryptedContent = await crypto.subtle.decrypt({ name: 'AES-CBC', iv }, key, encryptedContent); - // const decodedContent = new TextDecoder().decode(decryptedContent); - // console.log('Decrypted Content:', decodedContent); - // return decodedContent; - // } - - // // Example usage - // (async () => { - // const keyData = "my-secret-key"; - // const content = "This is my test content to encrypt and decrypt."; - - // const { base64, iv } = await ae_util.encrypt_content(content, keyData); - // await ae_util.decrypt_content(base64, iv, keyData); - // })(); - - // let journal_key: string = $state( 'my-secret-key-111'); - // let journal_key: string = $state($lq__journal_obj?.passcode); - // let journal_key: string = $state($lq__journal_obj?.passcode); - - // console.log('TEST: journal_key', journal_key); - - // $effect(() => { - // // A journal should always at least have a general passcode that can be used. If the private code is also found, then we should use the combined value as the key. - // if ($journals_sess.journal_kv[$lq__journal_obj?.id]?.journal_passcode_verified) { - // // For private - // journal_key = $lq__journal_obj?.combined_passcode; - // } else if ($lq__journal_obj?.passcode) { - // journal_key = $lq__journal_obj?.passcode; - // } else { - // 'temp-secret-key'; - // } - // console.log('TEST: journal_key', journal_key); - - // // if ($lq__journal_obj?.passcode) { - // // console.log('TEST: lq__journal_obj?.passcode', $lq__journal_obj?.passcode); - // // journal_key = $lq__journal_obj?.passcode; - // // } - // }); - - // $effect(async () => { - // if (tmp_entry_obj?.content_encrypted && trigger_decrypt) { - // trigger_decrypt = false; - - // handle_decrypt_content(); - - // } - - // // if (tmp_entry_obj?.content) { - // // content = tmp_entry_obj?.content; - - // // let encrypted_base64 = await ae_util.encrypt_content(content, journal_key); - // // encrypted_base64_string = encrypted_base64.base64; - // // encryption_iv = encrypted_base64.iv; - - // // let decrypted = await ae_util.decrypt_content(encrypted_base64_string, encryption_iv, journal_key); - // // decrypted_content = decrypted; - // // if (log_lvl) { - // // console.log('Decrypted content:', decrypted_content); - // // } - // // } - // // console.log('Encrypted content:', base64); - // // console.log('IV:', iv); - // }); - - // async function handle_decrypt_content() { - // log_lvl = 1; - // if (log_lvl) { - // console.log('TEST: handle_decrypt_content'); - // } - // let combined_data = tmp_entry_obj?.content_encrypted; - // let [encryption_iv_hex, encrypted_base64_string] = combined_data.split(':'); - // encryption_iv = new Uint8Array(encryption_iv_hex.match(/.{1,2}/g).map(byte => parseInt(byte, 16))); - // if (log_lvl) { - // console.log(`IV: ${encryption_iv}; Encrypted: ${encrypted_base64_string}`); - // } - - // let decrypted: string|null = null; - // try { - // decrypted = await ae_util.decrypt_content(encrypted_base64_string, encryption_iv, journal_key); - // } catch (error) { - // console.error('Error decrypting content:', error); - // alert('Failed to decrypt content. Please check the passcode.'); - // return; - // } - // // let decrypted = await ae_util.decrypt_content(encrypted_base64_string, encryption_iv, journal_key); - // // decrypted_content = 'XXX '+decrypted+' XXX'; - - // if (!decrypted) { - // alert('Failed to decrypt content. Please check the passcode.'); - // return; - // } - // decrypted_content = decrypted; - // if (log_lvl) { - // console.log('Decrypted content:', decrypted_content); - // } - // tmp_entry_obj.content = decrypted_content; - // // orig_entry_obj.content = decrypted_content; - // // tmp_entry_obj_changed = false; - - // // tmp_entry_obj.content_encrypted = null; - // } - + // *** Cryptographic Helpers (Simplified) async function handle_decrypt_string(encrypted_string: string, passcode: string) { if (log_lvl) console.log(`TEST: handle_decrypt_string: ${passcode}`, encrypted_string); - if (!encrypted_string) return ''; if (!passcode) return false; @@ -2181,45 +2059,14 @@ {#if tmp_entry_obj?.content_md_html} {@html tmp_entry_obj?.content_md_html} {:else if tmp_entry_obj?.content_encrypted && tmp_entry_obj?.private} -