简体   繁体   English

PHP纯文本加密-保持密钥安全

[英]PHP plain text encryption - keeping key safe

In a typical web scenario, a website user will come along, use a website, fill out a form, and transmit the data to the server for storage in the database. 在典型的Web场景中,网站用户将出现,使用网站,填写表格并将数据传输到服务器以存储在数据库中。 Now let's say we needed to ensure their address was encrypted as it was top secret, and only those with access to the back end of the website should be able to see what that address was - this is reasonably easy to achieve right? 现在,我们需要确保其地址是最高机密的,因此必须对其进行加密,并且只有那些有权访问网站后端的用户才能看到该地址是什么-这很容易实现,对吗? We would just store an encryption key server-side which would be used to generate the encrypted data, store the data in the DB, and we would just use the key again to decrypt it. 我们将只在服务器端存储一个加密密钥,该密钥将用于生成加密数据,将数据存储在数据库中,并且我们将再次使用该密钥对其进行解密。

Now supposing someone at the hosting company were to browse the files on your server - they could very easily get access to this encryption key, and then use it to decrypt any data they wanted, since all addresses in the database have been encrypted with the same key! 现在假设托管公司的某人将浏览您服务器上的文件-他们可以很容易地访问此加密密钥,然后使用它解密所需的任何数据,因为数据库中的所有地址均已使用相同的加密方式进行了加密键!

I am just trying to cover every base with the new security model, and in a "trust no one" policy I am looking at ways of stopping the hosting company from getting at the data too. 我只是想用新的安全模型覆盖每个基础,并且在“不信任任何人”策略中,我也在寻找阻止托管公司获取数据的方法。

So does anyone have any suggestions to prevent those with server access from obtaining the key and decrypting data? 那么,有人对防止具有服务器访问权限的人员获取密钥和解密数据有什么建议吗? Would password salting help in any way, or would they still be able to decrypt data quite easily. 密码盐化会以任何方式提供帮助,还是仍然能够相当轻松地解密数据。

I can't think of a way around the issue. 我想不出解决办法。 Does anyone have any suggestions to solve this particular problem? 有没有人有解决这个特定问题的建议?

Encrypt and decrypt in the browser everything sent to the host. 在浏览器中加密和解密发送到主机的所有内容。 Use a passphrase entered on the client to do the cryptography, and never send the passphrase to the host. 使用在客户端输入的密码来进行加密,并且永远不要将密码发送给主机。 There's a fuller description at Host-proof Hosting 防主机托管中有更完整的描述

I guess that's a risk when it comes to shared hostings. 我想这是共享主机的风险。 I'm using amazon aws for most of my projects and linode for my personal blog. 我的大多数项目都使用亚马逊Aws,个人博客使用linode。 Both solutions are in the model "you are your own sysadmin" and nobody peeks in your machines. 两种解决方案都在“您是您自己的系统管理员”模型中,没有人偷窥您的计算机。

If I was in your shoes, I'd use mcrypt with a variable key. 如果我不满意,请使用带有可变密钥的mcrypt。 For example, whe username field of the same row. 例如,同一行的用户名字段。 This way, for the data to be compromised, the intruder would need to get access to both your database and source code to figure out how to decrypt the data. 这样,对于入侵的数据,入侵者将需要访问您的数据库和源代码,以弄清楚如何解密数据。 At that point your problem would be far worse than a mere information leak. 到那时,您的问题将远不只是信息泄漏。

Well mostly hosting companies have access to all databases and files that is bad really bad. 好吧,大多数托管公司都可以访问所有不好的数据库和文件。

Few years ago I did some experimenting with encryption and decryption. 几年前,我做了一些加密和解密的实验。

The best way would be to have personal servers, but that isn't cheap. 最好的方法是拥有个人服务器,但这并不便宜。

Example RC4 encryption requires key to crypt data. 示例RC4加密需要密钥来加密数据。 Now tricky part is to make that key also encrypted with some other encryption like BASE 64 , ATOM 128. This wont make it be 100% secure 现在棘手的部分是使该密钥也使用其他一些加密方法(例如BASE 64和ATOM 128)进行加密。这不会使其成为100%安全的

But It will be really hard to decrypt data. 但是解密数据确实很难。

I hope you can understand me. 希望你能理解我。

Cheers :) 干杯:)

btw point is there is no 100% secure data. 顺便说一句,没有100%的安全数据。

If you don't need to be able to decrypt the data online, this is an ideal situation for public-key cryptography . 如果您不需要在线解密数据,那么这是公钥加密的理想情况。 In particular, a sealing API. 特别是密封API。 For example, using libsodium (PHP 7.2): 例如,使用libsodium(PHP 7.2):

Encryption 加密

$store_me = sodium_crypto_box_seal($plaintext, $box_publickey);
sodium_memzero($plaintext);

Decryption 解密

$plaintext = sodium_crypto_box_seal_open($stored_msg, $box_keypair);

If, however, you do need to be able to decrypt the data from the webserver, then anyone who accesses the webserver can just pilfer the keys and decrypt your data. 但是,如果您确实需要能够从Web服务器解密数据,那么访问Web服务器的任何人都可以窃取密钥并解密您的数据。 No cryptography algorithm can stop someone with the keys from decrypting messages. 没有密码算法可以阻止使用密钥的人解密消息。

Always start with a threat model . 始终从威胁模型入手。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM