使用 OpenSSL 和 PHP 存储数据?
对于其中一个角色,我通过电子邮件收到了一些来自人们的文件。这是非敏感数据,因此电子邮件没问题,但我想创建一个小型门户,人们可以在其中上传文件,只有当他们提交所需的所有文件时,我才会收到请求已完成的通知。
无论内容如何,我都希望安全地存储文档。这也让我开始考虑加密以满足我的其他需求。最初,我研究了 MySQL 中的 AES 加密,但普遍的共识是这没有什么好处,因为密钥在服务器中很容易获得。所以这让我开始考虑公钥/私钥加密。
这是我正在研究的计划,看看它是否有效,或者是否已经完成,但我只是找不到标准实现:
- 我生成一个公钥/私钥对。公钥发送至网络服务器,私钥则保留在我的计算机上。
- 用户通过 https 站点通过网页将文件上传到我的网络服务器。
- 上传脚本获取文件,使用公钥对其进行加密,并将其存储在文件系统或数据库中。
- 完成后,我会收到通知,然后连接到服务器并通过 SSH 或其他加密连接下载文件。
- 最后,我使用私钥在本地解密文件并根据需要进行处理。
在这种情况下我遗漏了什么缺陷吗?或者,如果有更好的方法来实现这一目标,任何人都可以指出我正确的方向吗?谢谢。
For one of roles, I've been receiving a couple of documents from people via email. It's non-sensitive data so email is fine, but I'd like to make a small portal where people can upload the files and only when they submit all the files required do I get notification that the request is complete.
Regardless of content, I'd like to store documents securely. It's also got me thinking about encryption in general for my other needs. Initially I looked at AES encryption in MySQL but the general consensus is this does no good as the key is readily available in the server. So this got me to thinking about public/private key encryption.
Here's the plan I'm researching to see if it would work or if it's already been done and I just can't find the standard implementation:
- I generate a public/private key pair. Public key goes to the web server, private key stays with me at my computer.
- User uploads file via the webpage to my web server through an https site.
- Upload script takes the file, encrypts it with the public key, and stores it in the file system or a database.
- Upon completion, I get notified and I connect to the server and download the files via SSH or other encrypted connection.
- Finally, I locally decrypt the files using the private key and process them as necessary.
Any flaws I'm missing in this scenario? Or if there's better ways to accomplish this, can anyone point me in the right direction? Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您的计划基本上表明您信任服务器,但不信任文件系统。当您使用共享服务或第 3 方备份,或者想要通过定期销毁加密密钥来实施数据销毁策略时,可以使用此方法。
如果您不想在上传之前加密文件给用户带来负担,那么这确实是您能做的最好的选择。
唯一的技巧是设置网络服务器,使其将上传的文件严格保留在内存中,直到您对其进行加密。例如,PHP 默认情况下会在调用脚本之前将上传的文件写入 /tmp。
Your plan basically says that you trust the server, but not the filesystem. This is used in cases where you are using a shared service or 3rd party backup, or want to enforce a data destruction policy via periodic destruction of the encryption key.
It's really the best you can do if you don't want to burden your users with encrypting the file before uploading.
The only trick is setting up the web server so that it keeps uploaded files strictly in memory until you encrypt them. PHP, for example, will by default write uploaded files to /tmp before even calling your script.