【发布时间】:2023-03-30 11:32:01
【问题描述】:
这是我的代码:
PasswordEncoder encoder = new Md5PasswordEncoder();
String hashedPass = encoder.encodePassword("passwordTest", null);
这是我的 pom.xml 文件:
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-core</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-config</artifactId>
</dependency>
但是我收到了这个错误:
Md5PasswordEncoder cannot be resolved to a type
和:
The import org.springframework.security.authentication.encoding cannot be resolved
【问题讨论】:
-
你不能用哈希加密一些东西。您可以散列密码,但请使用 SHA-3,而不是 MD5
-
@JCWasmx86 谢谢,但我想使用 Spring Security 的 MD5
-
你好像只做了
import org.springframework.security.authentication.encoding,试试import org.springframework.security.authentication.encoding.Md5PasswordEncoder -
使用
org.springframework.security.crypto.password.DelegatingPasswordEncoder,可用于不同类型的算法。它默认使用 bcrypt,但支持 LDAP、MD4、MD5、SHA-1、SHA-256、SHA256 等。 -
@JCWasmx86 我做了,但我收到了这个错误:无法解析导入 org.springframework.security.authentication.encoding
标签: java spring spring-security md5