Loading... # 加密工具类 ```java import org.apache.commons.codec.digest.DigestUtils; import java.util.Random; /** * @author MashiroT */ public class Encrypt { public static String generateSalt(int length) { StringBuilder sb = new StringBuilder(length); Random random = new Random(); char c; for (int i = 0; i < length; i++) { c = (char) (random.nextInt(94) + 33); sb.append(c); } return sb.toString(); } public static String encryptPassword(String password, String salt) { String addSaltPasswd = password.substring(0, password.length() / 2) + salt + password.substring(password.length() / 2); return DigestUtils.sha3_256Hex(addSaltPasswd).substring(7,57); } } ``` ```xml <!-- https://mvnrepository.com/artifact/commons-codec/commons-codec --> <dependency> <groupId>commons-codec</groupId> <artifactId>commons-codec</artifactId> <version>1.15</version> </dependency> ``` 最后修改:2022 年 10 月 11 日 © 允许规范转载 打赏 赞赏作者 支付宝微信 赞 本作品采用 CC BY-NC-SA 4.0 International License 进行许可。