@@ -75,11 +75,13 @@ def write(self, store: str, data: any, cfg_type=ConfigType.JSON, enc_key=None):
7575 elif cfg_type == ConfigType .JSONENC :
7676 assert enc_key is not None
7777 assert len (enc_key ) in [16 , 24 , 32 ]
78+ ivcipher = AES .new (enc_key , AES .MODE_ECB )
7879 cipher = AES .new (enc_key , AES .MODE_CBC )
7980 input_data = json .dumps (data )
8081 input_data = input_data .encode ('utf-8' )
8182 encrypted = cipher .encrypt (pad (input_data , AES .block_size ))
82- parsed = cipher .iv + encrypted
83+ enc_iv = ivcipher .encrypt (cipher .iv )
84+ parsed = enc_iv + encrypted
8385 mode += "b"
8486 stream = open (file_path , mode )
8587
@@ -113,7 +115,9 @@ def get(self, store: str, key: Union[str, list] = None, cfg_type=ConfigType.JSON
113115 elif cfg_type == ConfigType .JSONENC :
114116 assert enc_key is not None
115117 stream = open (file_path , "rb" )
116- iv = stream .read (16 )
118+ ivenc = stream .read (16 )
119+ ivcipher = AES .new (enc_key , AES .MODE_ECB )
120+ iv = ivcipher .decrypt (ivenc )
117121 cipher = AES .new (enc_key , AES .MODE_CBC , iv )
118122 encrypted_data = stream .read ()
119123 decrypted = cipher .decrypt (encrypted_data )
0 commit comments