在 java 5 中使用 AES 进行基于密码的加密(仅限 JCE)

发布于 2024-09-16 05:40:09 字数 431 浏览 3 评论 0原文

我想使用 AES(192 或 256 位),但我不知道如何从用户提供的密码生成密钥。

我已经通过这个线程,并且能够在Java 6中运行该程序。但是,我需要在 Java 5 中运行相同的程序,而 PBKDF2WithHmacSHA1 的 SecretKeyFactory 在 JDK 5 中不可用。

因此,本质上,我需要根据用户密码生成 192 或 256 位的 SecretKey,并且我想要一种安全的方法在java 5中做到这一点。

感谢帮助!

编辑#1 为了避免陷入困境,我现在使用 MD5(用户输入的密码 + 固定盐)中的 128 位作为 AES 的密钥。我知道这很糟糕,一旦我找到生成密钥的好方法就会改变它。

I would like to use AES (192 or 256 bits), but am stuck on how to generate a key from a user supplied password.

I have gone through this thread, and am able to run the program in Java 6. However, I need to run the same program in Java 5, and SecretKeyFactory for PBKDF2WithHmacSHA1 is not available in JDK 5.

So, essentially, I need to generate 192 or 256 bits for a SecretKey based on users password, and I would like a secure way to do that in java 5.

Help appreciated!

EDIT #1
Just to avoid getting stuck, I am now using 128 bits from MD5(user-entered-password + fixed-salt) as the key to AES. I know it sucks, and will change it the moment I figure out a good way to generate the key.

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

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

发布评论

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

评论(1

2024-09-23 05:40:09

您需要 PBKDF2WithHmacSHA1 有理由吗?

SecretKeyFactory 存在于 1.4.2 中,因此您可能会此处

Is there a reason you want PBKDF2WithHmacSHA1?

SecretKeyFactory existed in 1.4.2, so you might look here.

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