PasswordEncoder 配置 发表于 2021-12-12 | 更新于 2021-12-29 | 分类于 Java | 阅读次数: | 字数: 1.2k | 时长 ≈ 1 分钟 标签 spring spring-security PasswordEncoder 配置123456789101112131415161718192021222324252627@Beanpublic PasswordEncoder passwordEncoder() { String bcrypt = "bcrypt"; BCryptPasswordEncoder encoder = new BCryptPasswordEncoder(); Map<String, PasswordEncoder> encoders = new HashMap<>(8); encoders.put(bcrypt, new BCryptPasswordEncoder()); encoders.put("pbkdf2", new Pbkdf2PasswordEncoder()); encoders.put("scrypt", new SCryptPasswordEncoder()); // md // encoders.put("md4", new Md4PasswordEncoder()); // encoders.put("md5", new MessageDigestPasswordEncoder("MD5")); // sha // encoders.put("sha1", new StandardPasswordEncoder("SHA-1", "")); // encoders.put("sha256", new StandardPasswordEncoder()); // encoders.put("sha384", new StandardPasswordEncoder("SHA-384", "")); // encoders.put("sha512", new StandardPasswordEncoder("SHA-512", "")); // sm3 // encoders.put("sm3", new SM3PasswordEncoder()); // ldap // encoders.put("ldap", new LdapShaPasswordEncoder()); //idForEncode is default for encoder DelegatingPasswordEncoder delegating = new DelegatingPasswordEncoder(bcrypt, encoders); // 如果都不匹配以上加密方式,则使用默认方式 delegating.setDefaultPasswordEncoderForMatches(encoder); return delegating;} 本文作者: forever杨 本文链接: https://blog.yl-online.top/posts/583c9124.html 版权声明: 本博客所有文章除特别声明外,均采用 BY-NC-SA 许可协议。如果文章内容对你有用,请记录到你的笔记中。本博客站点随时会停止服务,请不要收藏、转载!