Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Storing encrypted files inside a database

I'm using PyCrypto to store some files inside a SQLITE database.

I'm using 4 fields :
the name of the file,
the length of the file (in bytes)
the SHA512 hash of the file
the encrypted file (with AES and then base64 to ASCII).

I need all the fields to show some info about the file without decrypting it.

The question is : is it secure to store the data like this ?
For example, the first characters of a ZIP file, or executable file are always the same, and if you already know the hash and the length of the file ... is it possible to decrypt the file, maybe partially ?

If it's not secure, how can I store some information about the file to index the files without decrypting them ? (information like length, hash, name, tags, etc)

(I use python, but you can give examples in any language)

like image 471
Cristi Constantin Avatar asked Sep 07 '26 05:09

Cristi Constantin


1 Answers

Data encrypted with AES has the same length as the plain data (give or take some block padding), so giving original length away doesn't harm security. SHA512 is a strong cryptographic hash designed to provide minimal information about the original content, so I don't see a problem here either.

Therefore, I think your scheme is quite safe. Any information "exposed" by it is negligible. Key management will probably be a much bigger concern anyway.

like image 116
Eli Bendersky Avatar answered Sep 10 '26 10:09

Eli Bendersky