From 31bd7f4b885d3402cb7d3a373e06756371fd7b5b Mon Sep 17 00:00:00 2001 From: lijiarao <136157943@qq.com> Date: Sun, 5 Nov 2023 15:10:06 +0800 Subject: [PATCH] =?UTF-8?q?update=20=E6=A0=BC=E5=BC=8F=E5=8C=96PasswordUti?= =?UTF-8?q?l.java?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/jero/common/util/PasswordUtil.java | 31 +++++-------------- 1 file changed, 7 insertions(+), 24 deletions(-) diff --git a/jero-boot-base/jero-boot-base-core/src/main/java/com/jero/common/util/PasswordUtil.java b/jero-boot-base/jero-boot-base-core/src/main/java/com/jero/common/util/PasswordUtil.java index dbb6a856..ff2cb8c1 100644 --- a/jero-boot-base/jero-boot-base-core/src/main/java/com/jero/common/util/PasswordUtil.java +++ b/jero-boot-base/jero-boot-base-core/src/main/java/com/jero/common/util/PasswordUtil.java @@ -75,24 +75,18 @@ public class PasswordUtil { /** * 加密明文字符串 - * - * @param plaintext - * 待加密的明文字符串 - * @param password - * 生成密钥时所使用的密码 - * @param salt - * 盐值 + * @param plaintext 待加密的明文字符串 + * @param password 生成密钥时所使用的密码 + * @param salt 盐值 * @return 加密后的密文字符串 * @throws Exception */ public static String encrypt(String plaintext, String password, String salt) { - Key key = getPBEKey(password); byte[] encipheredData = null; PBEParameterSpec parameterSpec = new PBEParameterSpec(salt.getBytes(), ITERATIONCOUNT); try { Cipher cipher = Cipher.getInstance(ALGORITHM); - cipher.init(Cipher.ENCRYPT_MODE, key, parameterSpec); //update-begin-author:sccott date:20180815 for:中文作为用户名时,加密的密码windows和linux会得到不同的结果 gitee/issues/IZUD7 encipheredData = cipher.doFinal(plaintext.getBytes("utf-8")); @@ -111,24 +105,18 @@ public class PasswordUtil { * @throws Exception */ public static String encrypt(String plaintext) { - return encrypt(plaintext, ALGORITHM, Salt); } /** * 解密密文字符串 - * - * @param ciphertext - * 待解密的密文字符串 - * @param password - * 生成密钥时所使用的密码(如需解密,该参数需要与加密时使用的一致) - * @param salt - * 盐值(如需解密,该参数需要与加密时使用的一致) + * @param ciphertext 待解密的密文字符串 + * @param password 生成密钥时所使用的密码(如需解密,该参数需要与加密时使用的一致) + * @param salt 盐值(如需解密,该参数需要与加密时使用的一致) * @return 解密后的明文字符串 * @throws Exception */ public static String decrypt(String ciphertext, String password, String salt) { - Key key = getPBEKey(password); byte[] passDec = null; PBEParameterSpec parameterSpec = new PBEParameterSpec(salt.getBytes(), ITERATIONCOUNT); @@ -139,7 +127,6 @@ public class PasswordUtil { passDec = cipher.doFinal(hexStringToBytes(ciphertext)); } - catch (Exception e) { // TODO: handle exception } @@ -149,12 +136,9 @@ public class PasswordUtil { return new String(passDec); } } - /** * 自定义解密密文字符串 - * - * @param ciphertext - * 待解密的密文字符串 + * @param ciphertext 待解密的密文字符串 * @return 解密后的明文字符串 * @throws Exception */ @@ -164,7 +148,6 @@ public class PasswordUtil { }else { return ""; } - } /**