yat*_*at0 3 php security api android key
所以我一直在搜索关于整个私有 API 密钥安全性的一段时间,我对我应该采取的方法感到有些困惑,因为我还没有找到与我有相同特定问题/方法的人。
我正在开发一个通过第三方 API 运行的 Android 应用程序,我通过请求私钥获得了访问权限。现在,2点:
因此,从这里您可以看到,我并没有尝试在应用程序代码中隐藏 API 密钥,也没有尝试使用用户 ID 和签名来允许访问我的类型的 API 并连续访问原始 API..
问题是,尽管无法在浏览器中看到 php 代码,但以其他方式这样做并非不可能,所以我在那里存储我的密钥也不安全。所以我的问题很简单,这仍然是我用来隐藏我的私有 API 密钥的最佳方法,还是我应该重新考虑我完成所有这些过程的方式?
小智 5
如果我理解正确的话,您不希望将 API 密钥存储在您的公共 Web 文件夹中,因为它可能会在某些条件下公开访问。
我遵循的建议是将 API 密钥存储在根 Web 文件夹之外的文件中。然后,您需要/将该文件包含在公共文件夹的脚本中。
在 Linux 环境中,是这样的:
/var/www/your_script.php (public access)
/var/secure/api_key.php (private, web server doesn't access this directory)
Run Code Online (Sandbox Code Playgroud)
在 your_script.php 中
require_once 'api_key.php'; // example only, you will need to use the correct path
echo $api_key; // testing, you can use the key in the script
Run Code Online (Sandbox Code Playgroud)
在 api_key.php 中
$api_key = '15r723er8q5re';
Run Code Online (Sandbox Code Playgroud)