在我们的服务器上,我们有几个通过 API 登录外部帐户的定期作业。目前,这些密码是硬编码的(明文)。我们将把它们存储在数据库中并希望加密密码,但我们必须能够解密它们才能登录到外部站点。有没有办法安全地存储这些密码,而无需明文存储另一个密码以进行加密/解密? (这似乎是一个常见问题,但我对安全术语不够熟悉,无法对其进行分类)。谢谢!
最佳答案
您要实现的目标与 this question 非常相似.理想情况下,您不想将这些 secret 保存在数据库中,而是希望它们尽可能远离您的应用程序。为什么?因为通过这种方式,您至少可以将应用程序本身排除在攻击面之外,并且访问这些密码会更加困难。
在您的情况下,您希望使用密码保护加密 key 。这意味着您必须将密码存储在某处。你应该再次加密那个密码吗?这会导致恶性循环——这就是我在这部分答案中的意思:
... What brings us to that resource. It's really a hen-and-egg problem with key stores and passwords. The only really clean solution to this is entering the passwords manually each time the app/database is started. But this tends to be a real problem (think of: crash in the middle of the night), so people tend to store the passwords in a text file on the file system. It's acceptable as long as you follow some guidelines:...
如果你加密一些东西,那么就有一个 secret 资源,涉及到的 key 。保守 secret 的理想方法是,如引用中所述,记住它并手动输入它,这样就不会留下任何痕迹。由于这通常是不可管理的,因此您不得不接受比内存更不安全但比以纯文本形式存储 secret 更好的方法。
与该帖子中的相同建议适用于您在文件中存储 secret 密码的情况。作为替代方案,您可以尝试利用操作系统安全存储设施,例如 Windows Data Protection .
关于Java - 外部站点的密码加密/解密,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7044294/