From 0231d6d30d83e23fc0fb7edfd84e8ac6a15d7b7e Mon Sep 17 00:00:00 2001
From: kk <1910333201@qq.com>
Date: Fri, 24 Nov 2023 14:05:38 +0800
Subject: [PATCH] =?UTF-8?q?=E6=B5=AA=E6=BD=AE=E5=8A=A0=E5=AF=86=E7=9A=84?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../encrypt/AisinoInvoiceEncryptUtil.java | 84 ++-----------------
1 file changed, 6 insertions(+), 78 deletions(-)
diff --git a/jianshui-common/src/main/java/com/jianshui/common/utils/encrypt/AisinoInvoiceEncryptUtil.java b/jianshui-common/src/main/java/com/jianshui/common/utils/encrypt/AisinoInvoiceEncryptUtil.java
index 8d97607..8190ad2 100644
--- a/jianshui-common/src/main/java/com/jianshui/common/utils/encrypt/AisinoInvoiceEncryptUtil.java
+++ b/jianshui-common/src/main/java/com/jianshui/common/utils/encrypt/AisinoInvoiceEncryptUtil.java
@@ -23,19 +23,12 @@ import java.security.SecureRandom;
public class AisinoInvoiceEncryptUtil {
private static final String ALGORITHM = "AES/GCM/NoPadding";
- private static final int KEY_SIZE = 128; // 密钥长度为128位
private static final int IV_LENGTH = 12; // 初始化向量长度为12字节(96位)
private static final int TAG_LENGTH = 16; // GCM模式的认证标签长度为16字节
+ /** 加密共有两种方法 一、DES 二、AES*/
- /**
- *
- * 方法名称:encrypt
- * 加密方法
- *
- * @param xmlStr 需要加密的消息字符串
- * @return 加密后的字符串
- */
+ /** 一、DES加密方法*/
public static String encrypt(String xmlStr, String mkey) {
byte[] encrypt = {};
@@ -77,23 +70,7 @@ public class AisinoInvoiceEncryptUtil {
}
- /**
- *
- * 方法名称:DES_CBC_Encrypt
- * 功能描述:
- *
- *
- * 经过封装的DES/CBC加密算法,如果包含中文,请注意编码。
- *
- *
- *
- *
- * @param sourceBuf 需要加密内容的字节数组。
- * @param deskey KEY 由8位字节数组通过SecretKeySpec类转换而成。
- * @param ivParam IV偏转向量,由8位字节数组通过IvParameterSpec类转换而成。
- * @return 加密后的字节数组
- * @throws Exception
- */
+ /** DES加密接口*/
public static byte[] DES_CBC_Encrypt(byte[] sourceBuf,
SecretKeySpec deskey, IvParameterSpec ivParam) throws Exception {
byte[] cipherByte;
@@ -119,7 +96,6 @@ public class AisinoInvoiceEncryptUtil {
byte[] ciphertext = cipher.doFinal(sourceBuf);
- // 将初始化向量和密文拼接在一起
byte[] result = new byte[IV_LENGTH + ciphertext.length];
System.arraycopy(iv, 0, result, 0, IV_LENGTH);
System.arraycopy(ciphertext, 0, result, IV_LENGTH, ciphertext.length);
@@ -137,7 +113,7 @@ public class AisinoInvoiceEncryptUtil {
}
- /** AES加密方法*/
+ /** 二、AES加密方法*/
public static String encryptAES(String xmlStr, String mkey) {
byte[] encrypt = {};
@@ -175,23 +151,7 @@ public class AisinoInvoiceEncryptUtil {
return bytesToHex(temp);
}
- /**
- *
- * 方法名称:MD5Hash
- * 功能描述:
- *
- *
- * MD5,进行了简单的封装,以适用于加,解密字符串的校验。
- *
- *
- *
- *
- * @param buf 需要MD5加密字节数组。
- * @param offset 加密数据起始位置。
- * @param length 需要加密的数组长度。
- * @return
- * @throws Exception
- */
+
public static byte[] MD5Hash(byte[] buf, int offset, int length)
throws Exception {
MessageDigest md = MessageDigest.getInstance("MD5");
@@ -200,21 +160,6 @@ public class AisinoInvoiceEncryptUtil {
}
- /**
- *
- * 方法名称:addMD5
- * 功能描述:
- *
- *
- * MD校验码 组合方法,前16位放MD5Hash码。 把MD5验证码byte[],加密内容byte[]组合的方法。
- *
- *
- *
- *
- * @param md5Byte 加密内容的MD5Hash字节数组。
- * @param bodyByte 加密内容字节数组
- * @return 组合后的字节数组,比加密内容长16个字节。
- */
public static byte[] addMD5(byte[] md5Byte, byte[] bodyByte) {
int length = bodyByte.length + md5Byte.length;
byte[] resutlByte = new byte[length];
@@ -232,20 +177,6 @@ public class AisinoInvoiceEncryptUtil {
}
- /**
- *
- * 方法名称:getKeyIV
- * 功能描述:
- *
- *
- *
- *
- *
- *
- * @param encryptKey
- * @param key
- * @param iv
- */
public static void getKeyIV(String encryptKey, byte[] key, byte[] iv) {
// 密钥Base64解密
BASE64Decoder decoder = new BASE64Decoder();
@@ -277,10 +208,7 @@ public class AisinoInvoiceEncryptUtil {
System.out.println(keyHex);
String str = "test";
-// String key = "LTEO+oOgWMsuQAOUglqXuQ=="; // 2233
- String key = "c5fdd10b2abd23b6c1c077935da40fca"; // 2233
-// str = encrypt(str, key);
-// System.out.println(str);
+ String key = "iAJ9xpsGu1QfOy7ZU0w0IA++";
System.out.println(encryptAES(str,key));