Work on passcodes and encryption
This commit is contained in:
@@ -720,6 +720,8 @@ export async function db_save_ae_obj_li__journal(
|
||||
passcode: obj.passcode, // For Journal Entry encryption password
|
||||
passcode_timeout: obj.passcode_timeout,
|
||||
|
||||
private_passcode: obj.private_passcode, // Combine with Journal passcode to encrypt and decrypt Entries
|
||||
|
||||
auth_key: obj.auth_key, // For Journal authorization without sign in
|
||||
|
||||
enable: obj.enable,
|
||||
@@ -738,6 +740,8 @@ export async function db_save_ae_obj_li__journal(
|
||||
// tmp_sort_1: `${obj.original_datetime}_${obj.group}_${obj.priority}_${obj.sort}`,
|
||||
// tmp_sort_2: `${obj.group}_${obj.original_datetime}_${obj.priority}_${obj.sort}`,
|
||||
|
||||
combined_passcode: `${obj.passcode}:${obj.private_passcode}`, // Combined Journal passcode and Journal private passcode to encrypt and decrypt Entries
|
||||
|
||||
// From SQL view
|
||||
journal_entry_count: obj.journal_entry_count,
|
||||
|
||||
@@ -834,6 +838,8 @@ let properties_to_save = [
|
||||
'passcode', // For Journal Entry encryption password
|
||||
'passcode_timeout',
|
||||
|
||||
'private_passcode', // Combine with Journal passcode to encrypt and decrypt Entries
|
||||
|
||||
'auth_key', // For Journal authorization without sign in
|
||||
|
||||
'enable',
|
||||
@@ -852,6 +858,8 @@ let properties_to_save = [
|
||||
// tmp_sort_1: `${obj.original_datetime}_${obj.group}_${obj.priority}_${obj.sort}`,
|
||||
// tmp_sort_2: `${obj.group}_${obj.original_datetime}_${obj.priority}_${obj.sort}`,
|
||||
|
||||
'combined_passcode',
|
||||
|
||||
// From SQL view
|
||||
'journal_entry_count',
|
||||
|
||||
@@ -945,6 +953,8 @@ export async function process_ae_obj__journal_props(
|
||||
passcode: obj.passcode, // For Journal Entry encryption password
|
||||
passcode_timeout: obj.passcode_timeout,
|
||||
|
||||
private_passcode: obj.private_passcode, // Combine with Journal passcode to encrypt and decrypt Entries
|
||||
|
||||
auth_key: obj.auth_key, // For Journal authorization without sign in
|
||||
|
||||
enable: obj.enable,
|
||||
@@ -963,6 +973,8 @@ export async function process_ae_obj__journal_props(
|
||||
// tmp_sort_1: `${obj.original_datetime}_${obj.group}_${obj.priority}_${obj.sort}`,
|
||||
// tmp_sort_2: `${obj.group}_${obj.original_datetime}_${obj.priority}_${obj.sort}`,
|
||||
|
||||
combined_passcode: `${obj.passcode}:${obj.private_passcode}`, // Combined Journal passcode and Journal private passcode to encrypt and decrypt Entries
|
||||
|
||||
// From SQL view
|
||||
journal_entry_count: obj.journal_entry_count,
|
||||
|
||||
|
||||
@@ -94,6 +94,10 @@ let journals_session_data_struct: key_val = {
|
||||
|
||||
tmp_obj: {},
|
||||
},
|
||||
|
||||
journal_kv: {
|
||||
// journal_id: {},
|
||||
},
|
||||
};
|
||||
// console.log(`AE Stores - App Journals Session Storage Data:`, journals_session_data_struct);
|
||||
export let journals_sess = writable(journals_session_data_struct);
|
||||
|
||||
@@ -71,6 +71,8 @@ export interface Journal {
|
||||
passcode?: null|string; // For Journal Entry encryption password
|
||||
passcode_timeout?: null|number; // Timeout in seconds
|
||||
|
||||
private_passcode?: null|string; // Combine with the Journal passcode for Journal Entry encryption password
|
||||
|
||||
auth_key?: null|string; // For Journal authorization without sign in
|
||||
|
||||
enable: null|boolean;
|
||||
@@ -89,6 +91,8 @@ export interface Journal {
|
||||
tmp_sort_2?: null|string;
|
||||
tmp_sort_3?: null|string;
|
||||
|
||||
combined_passcode?: null|string; // For Journal Entry encryption password
|
||||
|
||||
// Additional fields for convenience (database views)
|
||||
file_count?: null|number; // Only files directly under a journal
|
||||
journal_file_id_li_json?: null|string;
|
||||
|
||||
@@ -91,16 +91,10 @@ export let split_iv_and_base64 = function split_iv_and_base64(
|
||||
if (log_lvl) {
|
||||
console.log(`IV: ${iv}; Encrypted:`, base64);
|
||||
}
|
||||
|
||||
// const [ivBase64, base64] = combined.split(':');
|
||||
// const iv = Uint8Array.from(atob(ivBase64), c => c.charCodeAt(0));
|
||||
// if (log_lvl) {
|
||||
// console.log(`IV: ${iv}; Encrypted: ${base64}`);
|
||||
// }
|
||||
return { iv, base64 };
|
||||
}
|
||||
|
||||
// Updated 2025-05-08
|
||||
// Updated 2025-05-15
|
||||
export let decrypt_wrapper = async function decrypt_wrapper(
|
||||
combined: string,
|
||||
keyData: string
|
||||
@@ -110,11 +104,17 @@ export let decrypt_wrapper = async function decrypt_wrapper(
|
||||
return '';
|
||||
}
|
||||
const { iv, base64 } = split_iv_and_base64(combined);
|
||||
const decrypted = await decrypt_content(base64, iv, keyData);
|
||||
if (log_lvl > 1) {
|
||||
console.log(`IV: ${iv}; Decrypted:`, decrypted);
|
||||
} else if (log_lvl) {
|
||||
console.log(`IV: ${iv}`);
|
||||
let decrypted;
|
||||
try {
|
||||
decrypted = await decrypt_content(base64, iv, keyData);
|
||||
if (log_lvl > 1) {
|
||||
console.log(`IV: ${iv}; Decrypted:`, decrypted);
|
||||
} else if (log_lvl) {
|
||||
console.log(`IV: ${iv}`);
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Decryption failed:', error);
|
||||
return '';
|
||||
}
|
||||
return decrypted;
|
||||
}
|
||||
Reference in New Issue
Block a user