From 1c4b0631f90aa86e5d3b3b26b719471326c44d45 Mon Sep 17 00:00:00 2001 From: ZhouXY108 Date: Wed, 15 Nov 2023 23:04:12 +0800 Subject: [PATCH] =?UTF-8?q?=E5=B0=81=E8=A3=85=20Hashers=20=E7=B1=BB?= =?UTF-8?q?=EF=BC=8C=E6=96=B9=E4=BE=BF=E4=BD=BF=E7=94=A8=20guava=20?= =?UTF-8?q?=E5=B0=81=E8=A3=85=E7=9A=84=E5=93=88=E5=B8=8C=E5=B7=A5=E5=85=B7?= =?UTF-8?q?=E7=B1=BB=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../plusone/commons/security/Hashers.java | 60 +++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 src/main/java/xyz/zhouxy/plusone/commons/security/Hashers.java diff --git a/src/main/java/xyz/zhouxy/plusone/commons/security/Hashers.java b/src/main/java/xyz/zhouxy/plusone/commons/security/Hashers.java new file mode 100644 index 0000000..adff3c3 --- /dev/null +++ b/src/main/java/xyz/zhouxy/plusone/commons/security/Hashers.java @@ -0,0 +1,60 @@ +package xyz.zhouxy.plusone.commons.security; + +import com.google.common.hash.Hasher; +import com.google.common.hash.Hashing; + +/** + *

+ * 使用摘要算法推荐使用 guava 的 hash 包。 + *

+ *

+ * 密码加密推荐使用 {@link org.mindrot.jbcrypt.BCrypt}。 + *

+ */ +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"); + } +}