diff --git a/hutool-crypto/src/main/java/org/dromara/hutool/crypto/bc/ECKeyUtil.java b/hutool-crypto/src/main/java/org/dromara/hutool/crypto/bc/ECKeyUtil.java index 2ce7e5940..2e28034c1 100644 --- a/hutool-crypto/src/main/java/org/dromara/hutool/crypto/bc/ECKeyUtil.java +++ b/hutool-crypto/src/main/java/org/dromara/hutool/crypto/bc/ECKeyUtil.java @@ -49,6 +49,7 @@ import java.security.PrivateKey; import java.security.PublicKey; import java.security.spec.ECPublicKeySpec; import java.security.spec.KeySpec; +import java.util.Objects; /** * 椭圆曲线EC(Elliptic Curves)密钥参数相关工具类封装 @@ -339,7 +340,9 @@ public class ECKeyUtil { if (null == d) { return null; } - return toPrivateParams(BigIntegers.fromUnsignedByteArray(SecureUtil.decode(d)), domainParameters); + return toPrivateParams( + BigIntegers.fromUnsignedByteArray(Objects.requireNonNull(SecureUtil.decode(d))), + domainParameters); } /** diff --git a/hutool-crypto/src/test/java/org/dromara/hutool/crypto/asymmetric/Issue3728Test.java b/hutool-crypto/src/test/java/org/dromara/hutool/crypto/asymmetric/Issue3728Test.java new file mode 100644 index 000000000..a2294d0c0 --- /dev/null +++ b/hutool-crypto/src/test/java/org/dromara/hutool/crypto/asymmetric/Issue3728Test.java @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2024 Hutool Team and hutool.cn + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.dromara.hutool.crypto.asymmetric; + +import org.junit.jupiter.api.Test; + +public class Issue3728Test { + @Test + void sm2Test() { + String publicKey="04beab9c2b800c03263b2d9cfcc832eb6827d5b62dc2ec7f8503c8832799af13b057d6b5bf5bc6c144753f3aa8b6cef8acb00a379a4fbed2f90c546fc2b4586bb0"; + String privateKey="3920cfc4828339b34da62b97b44d49d3a9c7dc84d9e6732d4b18f681a339519c"; + final SM2 sm2 = new SM2(privateKey, publicKey); + } +}