封装 Hashers 类,方便使用 guava 封装的哈希工具类。

feature/security
ZhouXY108 2023-11-15 23:04:12 +08:00
parent 5ba888a9f2
commit 1c4b0631f9
1 changed files with 60 additions and 0 deletions

View File

@ -0,0 +1,60 @@
package xyz.zhouxy.plusone.commons.security;
import com.google.common.hash.Hasher;
import com.google.common.hash.Hashing;
/**
* <p>
* 使使 guava hash
* </p>
* <p>
* 使 {@link org.mindrot.jbcrypt.BCrypt}
* </p>
*/
public class Hashers {
/**
* guava {@link Hasher}
*/
public static Hasher sha256() {
return Hashing.sha256().newHasher();
}
/**
* guava {@link Hasher}
*/
public static Hasher sha384() {
return Hashing.sha384().newHasher();
}
/**
* guava {@link Hasher}
*/
public static Hasher sha512() {
return Hashing.sha512().newHasher();
}
/**
* guava {@link Hasher}
*
* @deprecated
*/
@Deprecated
public static Hasher sha1() {
return Hashing.sha1().newHasher();
}
/**
* guava {@link Hasher}
*
* @deprecated
*/
@Deprecated
public static Hasher md5() {
return Hashing.md5().newHasher();
}
private Hashers() {
throw new IllegalStateException("Utility class");
}
}