Spring安全密码哈希+盐

发布于 2024-12-28 12:51:05 字数 260 浏览 5 评论 0原文

我正在使用一个以明文形式存储密码的遗留应用程序。我已将应用程序移植到 spring 3 mvc + security。我还成功地让 spring security 使用 sha256 + 基于用户名的盐来处理身份验证和授权。这一切都很好,但是作为部署的一部分,我需要迁移现有数据库以使用新的密码架构。我不确定 Spring Security 如何使用盐对密码进行哈希处理,因此我无法编写可用于将旧的明文密码迁移到新的 sha256+salt 模式的 SQL 脚本。我可以使用任何文档或资源来解决这个问题吗?

I am working with a legacy application that stored passwords in plaintext. I have ported the application to spring 3 mvc + security. I have also successfully gotten spring security handling the authentication and authorization using sha256 + a salt based on the username. This all works great, however as part of the deployment, I will need to migrate the existing database to use the new password schema. I am not sure how spring security does it's password hashing with a salt, so i am unable to write a sql script that can be used to migrate the old plaintext passwords to the new sha256+salt schema. Is there any documentation or resources that I can use to figure this out?

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

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

发布评论

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

评论(2

城歌 2025-01-04 12:51:05

这记录在 BasePasswordEncoder

生成的密码将采用password{salt}的形式。

因此,在您的情况下,您可以使用以下简单的代码计算加盐密码:

new ShaPasswordEncoder(256).encodePassword(oldPassword, randomSalt)

注意: ShaPasswordEncoder 扩展 BasePasswordEncoder

This is documented in BasePasswordEncoder:

The generated password will be in the form of password{salt}.

So in your case you can compute the salted password using this simple code:

new ShaPasswordEncoder(256).encodePassword(oldPassword, randomSalt)

Note: ShaPasswordEncoder extends BasePasswordEncoder.

零崎曲识 2025-01-04 12:51:05
  1. 如果您使用默认密码编码,则 源代码似乎很有用。 (选择适合您正在使用的版本的分支)。
  2. 您可以实现自己的密码编码器并定义盐的使用方式。
  1. If you are using the default password encode then the source seems useful. (Pick the branch appropiate for the version you are using).
  2. You can implement your own PasswordEncoder and define the way the salt is used.
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文