Java Web 应用程序和密钥库

发布于 2024-12-06 10:05:51 字数 262 浏览 3 评论 0原文

我正在设计一个小工具(Web 界面和 Web 服务),用于使用 RSA 私钥对一些数据进行签名。该应用程序将拥有多个私钥(即针对不同类型的 blob),并且将来我们可能会弃用某些密钥(并添加新的私钥)。

问题是我应该将 KeyStore 文件存储在哪里?将其添加到 META-INF 似乎不是一个好主意,因为它会被软件更新覆盖。其他选项是存储到 /etc/myapp/keys.keystore 之类的内容或存储到 blob 列中的表中。

那么,存储密钥库的“规范”方式是什么?

I'm designing a small tool (web interface and web services), for signing some blob's of data with a private RSA key. The application will have more than one private key (ie. for different types of blob's), and in the future we might deprecate some of the keys (and add new ones).

The question is where should I store the KeyStore file? Adding it to META-INF doesn't seems like a good idea, as it would be overwritten with a software update. Other options, would be to store to something like /etc/myapp/keys.keystore or to a table in a blob column.

So, what is the "canonical" way of storing a keystore?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

听闻余生 2024-12-13 10:05:51

我认为没有规范的方法。也许最好的选择是将密钥库放在应用程序外部,并配置其位置(例如通过 -Dkeystore.location=/home/.. (类似于 )。

I don't think there's a canonical way. Perhaps the best option would be to have the keystore external to the application, and configure it's location (for example via -Dkeystore.location=/home/.. (something similar to this).

最偏执的依靠 2024-12-13 10:05:51

过去,我将密钥库存储在文件系统上,作为扩展名为 .jks 的文件。相关应用程序始终以特定用户身份运行,因此我们将该文件放入用户主目录(的子目录)中。然后我们编写了一些代码,

String keystorePath = System.getProperty("ourapp.keystore.path");
File keystoreFile;
if (keystorePath!=null)
    keystoreFile = new File(keystorePath);
else
    keystoreFile = new File(System.getProperty("user.home"), "ourapp.jks");
if (!f.exists()) {
    // Some sort of whining, return
}
// ...load and deal with keystore...

我认为没有规范的方法可以做到这一点(尽管我可能是错的)。这种方法对于我们的用例来说效果很好。

In the past, I've stored keystores on the file system, as a file with the .jks extension. The app in question always runs as a particular user, so we put the file in (a subdirectory of) the user's home directory. We then had some code along the lines of

String keystorePath = System.getProperty("ourapp.keystore.path");
File keystoreFile;
if (keystorePath!=null)
    keystoreFile = new File(keystorePath);
else
    keystoreFile = new File(System.getProperty("user.home"), "ourapp.jks");
if (!f.exists()) {
    // Some sort of whining, return
}
// ...load and deal with keystore...

I don't think there's a canonical way to do this (though I might be wrong). This way has worked well for our use case.

韶华倾负 2024-12-13 10:05:51

我还没有尝试过这个,但看起来推荐的方法是使用 context.xml 中的环境条目。

Tomcat 文档

相关 stackoverflow 问题这里

另外,您如何描述如何实现加密听起来可能存在一些问题。阅读用户 erickson 在各种答案中的建议,了解如何正确执行此操作。首先是一个问题:Java 256 位 AES 基于密码的加密

I've not tried this, but it looks like the recommended way to do this is using environment entries in context.xml.

Tomcat docs here

Related stackoverflow question here

Also, how you are describing how you're going to implement the encryption sounds like there are potentially some problems with it. Read the user erickson's recommendations in various answers to see how to do this right. Here is a question to start with: Java 256-bit AES Password-Based Encryption

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文