From 1cf740cead4d2da210597c0c7ccadfe0d2c35b60 Mon Sep 17 00:00:00 2001 From: shenym3 Date: Fri, 17 Jan 2025 16:48:21 +0800 Subject: [PATCH] =?UTF-8?q?[fix]:[][=E5=B1=8F=E8=94=BDswagger]?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../modules/util/vir/PasswordHashUtil.java | 63 +++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100644 src/main/java/com/jeesite/modules/util/vir/PasswordHashUtil.java diff --git a/src/main/java/com/jeesite/modules/util/vir/PasswordHashUtil.java b/src/main/java/com/jeesite/modules/util/vir/PasswordHashUtil.java new file mode 100644 index 0000000..1d6adaf --- /dev/null +++ b/src/main/java/com/jeesite/modules/util/vir/PasswordHashUtil.java @@ -0,0 +1,63 @@ +package com.vir.ai.admin.utils; + +import javax.crypto.Cipher; +import javax.crypto.SecretKey; +import javax.crypto.SecretKeyFactory; +import javax.crypto.spec.IvParameterSpec; +import javax.crypto.spec.PBEKeySpec; +import javax.crypto.spec.SecretKeySpec; +import javax.xml.bind.DatatypeConverter; + +import org.springframework.util.Base64Utils; +import org.springframework.util.DigestUtils; + +import lombok.extern.slf4j.Slf4j; + +import java.nio.charset.StandardCharsets; +import java.security.MessageDigest; +import java.security.SecureRandom; +import java.security.spec.KeySpec; +import java.util.Base64; + +/** + * 符合业界安全标准的密码hash处理,涉及的加密算法不要改动!!! + * **/ +@Slf4j +public class PasswordHashUtil { + public static final String PBKDF2_ALGORITHM = "PBKDF2WithHmacSHA256"; + public static final int SALT_SIZE = 32; + public static final int HASH_SIZE = 256; + public static final int PBKDF2_ITERATIONS = 10000; + + public static void main(String[] args) throws Exception { + + } + + public static String decriptAES(String SecretText, String key, String iv) throws Exception { + try { + + byte[] keyBytes = key.getBytes(StandardCharsets.UTF_8); + byte[] ivBytes = iv.getBytes(StandardCharsets.UTF_8); + + SecretKeySpec secretKeySpec = new SecretKeySpec(keyBytes, "AES"); + IvParameterSpec ivParameterSpec = new IvParameterSpec(ivBytes); + + Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5Padding"); + + cipher.init(Cipher.DECRYPT_MODE, secretKeySpec, ivParameterSpec); + + byte[] decryptedBytes = cipher.doFinal(Base64.getDecoder().decode(SecretText)); + String decryptedResult = new String(decryptedBytes, StandardCharsets.UTF_8); + + return decryptedResult; + } + catch (Exception e) { + String msg = "AES解密失败 - " + e.getMessage(); + log.error(msg, e); + throw new RuntimeException(msg); + } + + } + + +} -- Gitee