|
|
@@ -7,6 +7,10 @@ import org.bouncycastle.pqc.math.linearalgebra.ByteUtils;
|
|
|
import javax.crypto.Cipher;
|
|
|
import javax.crypto.KeyGenerator;
|
|
|
import javax.crypto.spec.SecretKeySpec;
|
|
|
+import java.io.UnsupportedEncodingException;
|
|
|
+import java.net.URLDecoder;
|
|
|
+import java.net.URLEncoder;
|
|
|
+import java.nio.charset.StandardCharsets;
|
|
|
import java.security.Key;
|
|
|
import java.security.SecureRandom;
|
|
|
import java.security.Security;
|
|
|
@@ -83,6 +87,8 @@ public class Sm4Util {
|
|
|
byte[] cipherArray = encrypt_Ecb_Padding(keyData, srcData);
|
|
|
// byte[]-->hexString
|
|
|
cipherText = ByteUtils.toHexString(cipherArray);
|
|
|
+
|
|
|
+ URLEncoder.encode(cipherText, StandardCharsets.UTF_8.toString());
|
|
|
return cipherText;
|
|
|
} catch (Exception e) {
|
|
|
return paramStr;
|
|
|
@@ -139,6 +145,12 @@ public class Sm4Util {
|
|
|
* @explain 解密模式:采用ECB
|
|
|
*/
|
|
|
public static String decryptEcb(String hexKey, String cipherText) {
|
|
|
+
|
|
|
+ try {
|
|
|
+ cipherText = URLDecoder.decode(cipherText,StandardCharsets.UTF_8.toString());
|
|
|
+ } catch (UnsupportedEncodingException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
// 用于接收解密后的字符串
|
|
|
String decryptStr = "";
|
|
|
// hexString-->byte[]
|