I am currently building a website for a nursing home. I have already designed a scheme to store private data in my database, but I would like your opinion about it.
Basically, I have a table patient
which stores public (= non-sensitive) information about patients. Some other information (like name, address) are private one and need to be securely stored. I use a public/private key pair, generated by PHP OpenSSL and sent by the website manager. The passphrase is only known by people allowed to access private data (basically, healthcare providers).
I would like to store them in an other table. First question, is BLOB
the best column type (with MySQL) to store binary data. Or should I convert them (with base64
for example) and store them in a VARCHAR
column?
My patient_secure_data
table looks like this:
id INT AUTO_INCREMENT patient_id INT (FOREIGN KEY to patient.id) key VARCHAR(63) data BLOB env BLOB
It is a key-value table, where value are sealed by openssl_seal
. I need to store the third parameter ($env_keys
) to be able to decrypt data. So second question, why do I need this env_keys
if I have the passphrase of the private key when I call openssl_open
?
Third (and last) question, is it a safe database schema? I mean, can I guarantee that nobody without passphrase can see private data?
Note: I will also use the same key pair to encrypt files stored on disk. But database or files, I can't see any differences regarding security.
Regards,
Guillaume.
Sorry if my language is not perfect, I am not a native english speaker... I hope I made myself clear.