@@ -3,11 +3,23 @@ import { type Todo } from '../models/Todo';
33import { type User } from '../models/User' ;
44
55class LocalStorageRepository {
6+ private static encryptionKey = 'your-secure-key' ; // Replace with a securely managed key
7+
8+ private static encryptData ( data : string ) : string {
9+ // Implement encryption logic here
10+ return btoa ( data ) ; // Example: Base64 encoding (replace with actual encryption)
11+ }
12+
13+ private static decryptData ( data : string ) : string {
14+ // Implement decryption logic here
15+ return atob ( data ) ; // Example: Base64 decoding (replace with actual decryption)
16+ }
617 static getLocalStorageObject < T > ( key : string ) : T | null {
718 const value = localStorage . getItem ( key ) ;
819 if ( value ) {
920 try {
10- return JSON . parse ( value ) as T ;
21+ const decryptedData = LocalStorageRepository . decryptData ( value ) ;
22+ return JSON . parse ( decryptedData ) as T ;
1123 } catch ( e ) {
1224 throw new Error ( 'Could not parse local storage object' ) ;
1325 }
@@ -48,7 +60,8 @@ class LocalStorageRepository {
4860 }
4961
5062 static setLocalStorageObject < T > ( key : string , object : T ) : void {
51- localStorage . setItem ( key , JSON . stringify ( object ) ) ;
63+ const encryptedData = LocalStorageRepository . encryptData ( JSON . stringify ( object ) ) ;
64+ localStorage . setItem ( key , encryptedData ) ;
5265 }
5366
5467 static clearAll ( ) : void {
0 commit comments