Browse Source

fix sm2 bug

Looly 5 years ago
parent
commit
8102b31373

+ 1 - 0
CHANGELOG.md

@@ -12,6 +12,7 @@
 ### Bug修复
 * 【json   】     修复解析JSON字符串时配置无法传递问题
 * 【core   】     修复ServletUtil.readCookieMap空指针问题(issue#827@Github)
+* 【crypto 】     修复SM2中检查密钥导致的问题(issue#I1EC47@Gitee)
 
 -------------------------------------------------------------------------------------------------------------
 

+ 0 - 22
hutool-crypto/src/main/java/cn/hutool/crypto/asymmetric/SM2.java

@@ -182,7 +182,6 @@ public class SM2 extends AbstractAsymmetricCrypto<SM2> {
 		if (KeyType.PublicKey != keyType) {
 			throw new IllegalArgumentException("Encrypt is only support by public key");
 		}
-		checkKey(keyType);
 		return encrypt(data, new ParametersWithRandom(getCipherParameters(keyType)));
 	}
 
@@ -229,7 +228,6 @@ public class SM2 extends AbstractAsymmetricCrypto<SM2> {
 		if (KeyType.PrivateKey != keyType) {
 			throw new IllegalArgumentException("Decrypt is only support by private key");
 		}
-		checkKey(keyType);
 		return decrypt(data, getCipherParameters(keyType));
 	}
 
@@ -451,26 +449,6 @@ public class SM2 extends AbstractAsymmetricCrypto<SM2> {
 	}
 
 	/**
-	 * 检查对应类型的Key是否存在
-	 *
-	 * @param keyType key类型
-	 */
-	private void checkKey(KeyType keyType) {
-		switch (keyType) {
-			case PublicKey:
-				if (null == this.publicKey) {
-					throw new NullPointerException("No public key provided");
-				}
-				break;
-			case PrivateKey:
-				if (null == this.privateKey) {
-					throw new NullPointerException("No private key provided");
-				}
-				break;
-		}
-	}
-
-	/**
 	 * 获取{@link SM2Engine},此对象为懒加载模式
 	 *
 	 * @return {@link SM2Engine}

+ 0 - 2
hutool-crypto/src/test/java/cn/hutool/crypto/test/SM2Test.java

@@ -171,9 +171,7 @@ public class SM2Test {
 		String id = "31323334353637383132333435363738";
 
 		final SM2 sm2 = new SM2(d, x, y);
-
 		final String sign = sm2.signHex(data, id);
-
 		Assert.assertTrue(sm2.verifyHex(data, sign));
 	}
 }

+ 7 - 8
hutool-poi/src/main/java/cn/hutool/poi/excel/ExcelPicUtil.java

@@ -1,9 +1,8 @@
 package cn.hutool.poi.excel;
 
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
+import cn.hutool.core.collection.CollectionUtil;
+import cn.hutool.core.lang.Assert;
+import cn.hutool.core.util.StrUtil;
 import org.apache.poi.hssf.usermodel.HSSFClientAnchor;
 import org.apache.poi.hssf.usermodel.HSSFPicture;
 import org.apache.poi.hssf.usermodel.HSSFPictureData;
@@ -20,9 +19,9 @@ import org.apache.poi.xssf.usermodel.XSSFSheet;
 import org.apache.poi.xssf.usermodel.XSSFWorkbook;
 import org.openxmlformats.schemas.drawingml.x2006.spreadsheetDrawing.CTMarker;
 
-import cn.hutool.core.collection.CollectionUtil;
-import cn.hutool.core.lang.Assert;
-import cn.hutool.core.util.StrUtil;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
 
 /**
  * Excel图片工具类
@@ -87,7 +86,7 @@ public class ExcelPicUtil {
 	 * @return 图片映射,键格式:行_列,值:{@link PictureData}
 	 */
 	private static Map<String, PictureData> getPicMapXlsx(XSSFWorkbook workbook, int sheetIndex) {
-		final Map<String, PictureData> sheetIndexPicMap = new HashMap<String, PictureData>();
+		final Map<String, PictureData> sheetIndexPicMap = new HashMap<>();
 		final XSSFSheet sheet = workbook.getSheetAt(sheetIndex);
 		XSSFDrawing drawing;
 		for (POIXMLDocumentPart dr : sheet.getRelations()) {