From 25836328835ca4f017658ab546b654a5e5b92c09 Mon Sep 17 00:00:00 2001 From: 疯狂的狮子Li <15040126243@163.com> Date: 星期四, 25 四月 2024 12:50:42 +0800 Subject: [PATCH] update springboot 3.2.4 => 3.2.5 update mybatis-plus 3.5.5 => 3.5.6 适配更改代码 update springdoc 2.4.0 => 2.5.0 update easyexcel 3.3.3 => 3.3.4 update redisson 3.27.2 => 3.29.0 update lombok 1.18.30 => 1.18.32 update sms4j 3.2.0 => 3.2.1 --- ruoyi-common/ruoyi-common-encrypt/src/main/java/org/dromara/common/encrypt/core/encryptor/Sm4Encryptor.java | 24 ++++++------------------ 1 files changed, 6 insertions(+), 18 deletions(-) diff --git a/ruoyi-common/ruoyi-common-encrypt/src/main/java/org/dromara/common/encrypt/core/encryptor/Sm4Encryptor.java b/ruoyi-common/ruoyi-common-encrypt/src/main/java/org/dromara/common/encrypt/core/encryptor/Sm4Encryptor.java index 2a32faf..adaf674 100644 --- a/ruoyi-common/ruoyi-common-encrypt/src/main/java/org/dromara/common/encrypt/core/encryptor/Sm4Encryptor.java +++ b/ruoyi-common/ruoyi-common-encrypt/src/main/java/org/dromara/common/encrypt/core/encryptor/Sm4Encryptor.java @@ -1,13 +1,9 @@ package org.dromara.common.encrypt.core.encryptor; -import cn.hutool.core.util.StrUtil; -import cn.hutool.crypto.SmUtil; -import cn.hutool.crypto.symmetric.SM4; import org.dromara.common.encrypt.core.EncryptContext; import org.dromara.common.encrypt.enumd.AlgorithmType; import org.dromara.common.encrypt.enumd.EncodeType; - -import java.nio.charset.StandardCharsets; +import org.dromara.common.encrypt.utils.EncryptUtils; /** * sm4绠楁硶瀹炵幇 @@ -17,19 +13,11 @@ */ public class Sm4Encryptor extends AbstractEncryptor { - private final SM4 sm4; + private final EncryptContext context; public Sm4Encryptor(EncryptContext context) { super(context); - String password = context.getPassword(); - if (StrUtil.isBlank(password)) { - throw new IllegalArgumentException("SM4娌℃湁鑾峰緱绉橀挜淇℃伅"); - } - // sm4绠楁硶鐨勭閽ヨ姹傛槸16浣嶉暱搴� - if (16 != password.length()) { - throw new IllegalArgumentException("SM4绉橀挜闀垮害搴旇涓�16浣嶏紝瀹為檯涓�" + password.length() + "浣�"); - } - this.sm4 = SmUtil.sm4(password.getBytes(StandardCharsets.UTF_8)); + this.context = context; } /** @@ -49,9 +37,9 @@ @Override public String encrypt(String value, EncodeType encodeType) { if (encodeType == EncodeType.HEX) { - return sm4.encryptHex(value); + return EncryptUtils.encryptBySm4Hex(value, context.getPassword()); } else { - return sm4.encryptBase64(value); + return EncryptUtils.encryptBySm4(value, context.getPassword()); } } @@ -62,6 +50,6 @@ */ @Override public String decrypt(String value) { - return this.sm4.decryptStr(value); + return EncryptUtils.decryptBySm4(value, context.getPassword()); } } -- Gitblit v1.9.3