我应该如何在 PHP 应用程序中加密我的数据?
我尝试使用 Paypal PHP SDK,并注意到一条警告,提示我应该加密我的 API 用户名和密码,以便在生产环境中使用。我确实同意这个说法,但我想知道我应该如何去做。我目前没有任何线索。
以下是警告内容,仅供记录:
请勿在应用程序代码中嵌入纯文本凭据。这样做 不安全并且违背最佳实践。您的 API 凭证必须是 安全处理。请考虑对它们进行加密以用于任何 生产环境,并确保只有授权的个人 可以查看或修改它们。
提前致谢。
I was trying to use the Paypal PHP SDK and I noticed a warning that says I should encrypt my API username and password for use in production environments. I do agree on this statement, but I'm wondering how I should go about doing that. I currently have no clue.
Here's what the warning says, just for the record:
Do not embed plaintext credentials in your application code. Doing so
is insecure and against best practices. Your API credentials must be
handled securely. Please consider encrypting them for use in any
production environment, and ensure that only authorized individuals
may view or modify them.
Thanks in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
通常,您可以将这样的凭据存储在 Web 根目录之外的文件中。这限制了风险,但并没有完全消除风险。
如果他们可以看到您的代码(或者更糟糕的是,编辑它),那么他们无论如何都可以获得您的凭据。加密它意味着您需要将加密密钥放在与用户名/密码本身一样可见的地方。
Generally, you can store credentials like this in a file outside of the web root. This limits risk, but doesn't get rid of it entirely.
If they can see your code (or even worse, edit it), then they can get your credentials anyway. Encrypting it means you need your encryption key somewhere that would be just as visible as the username/password itself.
首先,设置一个加密密钥:
在数据库条目或其他文件中对其进行加密,并仅将加密的字符串存储在文件本身中:
稍后解密:
First, set an encryption key:
Encrypt it on DB entry or from another file and only store the encrypted string in the file itself:
Decrypt it later: