Best way to encrypt/decrypt a file uploaded via PHP for this purpose? -
i'm in process of prototyping file upload system service needs basic form of encryption files uploaded users. of files uploaded uploaded same directory in users can download , upload files freely, authorized users able delete files uploads.
with in mind, need know best way encrypt these files (via crypt()
or similar) storage in non-public-accessible directory purpose. considered using base 64 encode functions built php this, seemed if able write php script on server base 64 decrypt files stored on server, thereby rendering encryption protection useless.
in summary, need know best way implement (i.e. functions or classes use) meets following criteria:
- the function needs reversible in way users logged in via php's
$_session
variables can decrypt files encrypted. - encryption needs affect file types, whether images, text, binaries, documents, , decrypting files must yield file identical file encrypted (i.e. header intact).
i may worried more necessary, make easy use possible basic security. i'm not protecting particularly important such credit card information or trade secrets, users designing have peace-of-mind know there @ least some measures in place prevent hacking of files uploaded.
base64 not encryption.
if want strong encryption, you'll want think using gpg extension
then need consider system architecture.
if server needs encrypt/decrypt files, key need on server, , readable web server process. means if compromises server, have access need decrypt files!
even worse, since php app drives encryption/decryption, attacker needs access 1 of users' accounts.
encryption going save if attacker somehow gets access file storage directory, nothing else on server. that's unlikely scenario.
in case, sounds on-disk encryption overkill. if files not directly web-accessible, that's enough. focus instead on making sure host system secure (updated packages, firewall rules), , application secure (run under https, use best practices defeat sql injection , csrf attacks, require strong passwords, etc).
Comments
Post a Comment