Commit fb8c9a04 authored by wujiang's avatar wujiang

提交代码

parent e0d779c3
...@@ -56,6 +56,10 @@ ...@@ -56,6 +56,10 @@
<artifactId>*</artifactId> <artifactId>*</artifactId>
</exclusion> </exclusion>
<exclusion> <exclusion>
<groupId>org.bouncycastle</groupId>
<artifactId>bcprov-jdk16</artifactId>
</exclusion>
<exclusion>
<groupId>io.springfox</groupId> <groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId> <artifactId>springfox-swagger-ui</artifactId>
</exclusion> </exclusion>
......
package com.yeejoin.amos.boot.biz.common.utils; //package com.yeejoin.amos.boot.biz.common.utils;
//
import sun.reflect.ConstructorAccessor; //import sun.reflect.ConstructorAccessor;
import sun.reflect.FieldAccessor; //import sun.reflect.FieldAccessor;
import sun.reflect.ReflectionFactory; //import sun.reflect.ReflectionFactory;
//
import java.lang.reflect.AccessibleObject; //import java.lang.reflect.AccessibleObject;
import java.lang.reflect.Array; //import java.lang.reflect.Array;
import java.lang.reflect.Field; //import java.lang.reflect.Field;
import java.lang.reflect.Modifier; //import java.lang.reflect.Modifier;
import java.util.ArrayList; //import java.util.ArrayList;
import java.util.Arrays; //import java.util.Arrays;
import java.util.List; //import java.util.List;
//
/** ///**
* 动态枚举工具类 // * 动态枚举工具类
* // *
* @author DELL // * @author DELL
*/ // */
public class DynamicEnumUtil { //public class DynamicEnumUtil {
private static ReflectionFactory reflectionFactory = ReflectionFactory.getReflectionFactory(); // private static ReflectionFactory reflectionFactory = ReflectionFactory.getReflectionFactory();
//
private static void setFailsafeFieldValue(Field field, Object target, Object value) throws NoSuchFieldException, // private static void setFailsafeFieldValue(Field field, Object target, Object value) throws NoSuchFieldException,
IllegalAccessException { // IllegalAccessException {
//
// 反射访问私有变量 // // 反射访问私有变量
field.setAccessible(true); // field.setAccessible(true);
//
/** // /**
* 接下来,我们将字段实例中的修饰符更改为不再是final, // * 接下来,我们将字段实例中的修饰符更改为不再是final,
* 从而使反射允许我们修改静态final字段。 // * 从而使反射允许我们修改静态final字段。
*/ // */
Field modifiersField = Field.class.getDeclaredField("modifiers"); // Field modifiersField = Field.class.getDeclaredField("modifiers");
modifiersField.setAccessible(true); // modifiersField.setAccessible(true);
int modifiers = modifiersField.getInt(field); // int modifiers = modifiersField.getInt(field);
//
// 去掉修饰符int中的最后一位 // // 去掉修饰符int中的最后一位
modifiers &= ~Modifier.FINAL; // modifiers &= ~Modifier.FINAL;
modifiersField.setInt(field, modifiers); // modifiersField.setInt(field, modifiers);
//
FieldAccessor fa = reflectionFactory.newFieldAccessor(field, false); // FieldAccessor fa = reflectionFactory.newFieldAccessor(field, false);
fa.set(target, value); // fa.set(target, value);
} // }
//
private static void blankField(Class<?> enumClass, String fieldName) throws NoSuchFieldException, // private static void blankField(Class<?> enumClass, String fieldName) throws NoSuchFieldException,
IllegalAccessException { // IllegalAccessException {
for (Field field : Class.class.getDeclaredFields()) { // for (Field field : Class.class.getDeclaredFields()) {
if (field.getName().contains(fieldName)) { // if (field.getName().contains(fieldName)) {
AccessibleObject.setAccessible(new Field[]{field}, true); // AccessibleObject.setAccessible(new Field[]{field}, true);
setFailsafeFieldValue(field, enumClass, null); // setFailsafeFieldValue(field, enumClass, null);
break; // break;
} // }
} // }
} // }
//
private static void cleanEnumCache(Class<?> enumClass) throws NoSuchFieldException, IllegalAccessException { // private static void cleanEnumCache(Class<?> enumClass) throws NoSuchFieldException, IllegalAccessException {
// Sun (Oracle?!?) JDK 1.5/6 // // Sun (Oracle?!?) JDK 1.5/6
blankField(enumClass, "enumConstantDirectory"); // blankField(enumClass, "enumConstantDirectory");
// IBM JDK // // IBM JDK
blankField(enumClass, "enumConstants"); // blankField(enumClass, "enumConstants");
} // }
//
private static ConstructorAccessor getConstructorAccessor(Class<?> enumClass, Class<?>[] additionalParameterTypes) // private static ConstructorAccessor getConstructorAccessor(Class<?> enumClass, Class<?>[] additionalParameterTypes)
throws NoSuchMethodException { // throws NoSuchMethodException {
Class<?>[] parameterTypes = new Class[additionalParameterTypes.length + 2]; // Class<?>[] parameterTypes = new Class[additionalParameterTypes.length + 2];
parameterTypes[0] = String.class; // parameterTypes[0] = String.class;
parameterTypes[1] = int.class; // parameterTypes[1] = int.class;
System.arraycopy(additionalParameterTypes, 0, parameterTypes, 2, additionalParameterTypes.length); // System.arraycopy(additionalParameterTypes, 0, parameterTypes, 2, additionalParameterTypes.length);
return reflectionFactory.newConstructorAccessor(enumClass.getDeclaredConstructor(parameterTypes)); // return reflectionFactory.newConstructorAccessor(enumClass.getDeclaredConstructor(parameterTypes));
} // }
//
private static Object makeEnum(Class<?> enumClass, String value, int ordinal, Class<?>[] additionalTypes, // private static Object makeEnum(Class<?> enumClass, String value, int ordinal, Class<?>[] additionalTypes,
Object[] additionalValues) throws Exception { // Object[] additionalValues) throws Exception {
Object[] params = new Object[additionalValues.length + 2]; // Object[] params = new Object[additionalValues.length + 2];
params[0] = value; // params[0] = value;
params[1] = Integer.valueOf(ordinal); // params[1] = Integer.valueOf(ordinal);
System.arraycopy(additionalValues, 0, params, 2, additionalValues.length); // System.arraycopy(additionalValues, 0, params, 2, additionalValues.length);
return enumClass.cast(getConstructorAccessor(enumClass, additionalTypes).newInstance(params)); // return enumClass.cast(getConstructorAccessor(enumClass, additionalTypes).newInstance(params));
} // }
//
/** // /**
* 将枚举实例添加到作为参数提供的枚举类中 // * 将枚举实例添加到作为参数提供的枚举类中
* // *
* @param <T> // * @param <T>
* @param enumType 要修改的枚举类型 // * @param enumType 要修改的枚举类型
* @param enumName 添加的枚举类型名字 // * @param enumName 添加的枚举类型名字
* @param additionalTypes 枚举类型参数类型列表 // * @param additionalTypes 枚举类型参数类型列表
* @param additionalValues 枚举类型参数值列表 // * @param additionalValues 枚举类型参数值列表
* @return // * @return
*/ // */
@SuppressWarnings("unchecked") // @SuppressWarnings("unchecked")
public static <T extends Enum<?>> T addEnum(Class<T> enumType, String enumName, Class<?>[] additionalTypes, // public static <T extends Enum<?>> T addEnum(Class<T> enumType, String enumName, Class<?>[] additionalTypes,
Object[] additionalValues) { // Object[] additionalValues) {
//
// 0. 检查类型 // // 0. 检查类型
if (!Enum.class.isAssignableFrom(enumType)) { // if (!Enum.class.isAssignableFrom(enumType)) {
throw new RuntimeException("class " + enumType + " is not an instance of Enum"); // throw new RuntimeException("class " + enumType + " is not an instance of Enum");
} // }
//
// 1. 在枚举类中查找“$values”持有者并获取以前的枚举实例 // // 1. 在枚举类中查找“$values”持有者并获取以前的枚举实例
Field valuesField = null; // Field valuesField = null;
Field[] fields = enumType.getDeclaredFields(); // Field[] fields = enumType.getDeclaredFields();
for (Field field : fields) { // for (Field field : fields) {
if (field.getName().contains("$VALUES")) { // if (field.getName().contains("$VALUES")) {
valuesField = field; // valuesField = field;
break; // break;
} // }
} // }
AccessibleObject.setAccessible(new Field[]{valuesField}, true); // AccessibleObject.setAccessible(new Field[]{valuesField}, true);
//
try { // try {
// 2. 将他拷贝到数组 // // 2. 将他拷贝到数组
T[] previousValues = (T[]) valuesField.get(enumType); // T[] previousValues = (T[]) valuesField.get(enumType);
List<T> values = new ArrayList<T>(Arrays.asList(previousValues)); // List<T> values = new ArrayList<T>(Arrays.asList(previousValues));
//
// 3. 创建新的枚举项 // // 3. 创建新的枚举项
T newValue = (T) makeEnum(enumType, enumName, values.size(), additionalTypes, additionalValues); // T newValue = (T) makeEnum(enumType, enumName, values.size(), additionalTypes, additionalValues);
//
// 4. 添加新的枚举项 // // 4. 添加新的枚举项
values.add(newValue); // values.add(newValue);
//
// 5. 设定拷贝的数组,到枚举类型 // // 5. 设定拷贝的数组,到枚举类型
setFailsafeFieldValue(valuesField, null, values.toArray((T[]) Array.newInstance(enumType, 0))); // setFailsafeFieldValue(valuesField, null, values.toArray((T[]) Array.newInstance(enumType, 0)));
//
// 6. 清楚枚举的缓存 // // 6. 清楚枚举的缓存
cleanEnumCache(enumType); // cleanEnumCache(enumType);
return newValue; // return newValue;
} catch (Exception e) { // } catch (Exception e) {
throw new RuntimeException(e.getMessage(), e); // throw new RuntimeException(e.getMessage(), e);
} // }
} // }
} //}
\ No newline at end of file \ No newline at end of file
...@@ -14,10 +14,10 @@ ...@@ -14,10 +14,10 @@
<dependencies> <dependencies>
<dependency> <!--<dependency>
<groupId>org.springframework.cloud</groupId> <groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-client</artifactId> <artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
</dependency> </dependency>-->
<dependency> <dependency>
<groupId>org.springframework.boot</groupId> <groupId>org.springframework.boot</groupId>
...@@ -39,6 +39,10 @@ ...@@ -39,6 +39,10 @@
<groupId>org.typroject</groupId> <groupId>org.typroject</groupId>
<artifactId>*</artifactId> <artifactId>*</artifactId>
</exclusion> </exclusion>
<exclusion>
<groupId>org.bouncycastle</groupId>
<artifactId>bcprov-jdk16</artifactId>
</exclusion>
</exclusions> </exclusions>
</dependency> </dependency>
<dependency> <dependency>
......
...@@ -13,10 +13,10 @@ ...@@ -13,10 +13,10 @@
<name>amos-boot-data-equip</name> <name>amos-boot-data-equip</name>
<dependencies> <dependencies>
<dependency> <!--<dependency>
<groupId>org.springframework.cloud</groupId> <groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-client</artifactId> <artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
</dependency> </dependency>-->
<dependency> <dependency>
<groupId>org.springframework.boot</groupId> <groupId>org.springframework.boot</groupId>
...@@ -43,6 +43,10 @@ ...@@ -43,6 +43,10 @@
<groupId>org.typroject</groupId> <groupId>org.typroject</groupId>
<artifactId>*</artifactId> <artifactId>*</artifactId>
</exclusion> </exclusion>
<exclusion>
<groupId>org.bouncycastle</groupId>
<artifactId>bcprov-jdk16</artifactId>
</exclusion>
</exclusions> </exclusions>
</dependency> </dependency>
......
...@@ -15,62 +15,66 @@ ...@@ -15,62 +15,66 @@
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties> </properties>
<dependencies> <dependencies>
<dependency> <!--<dependency>
<groupId>org.springframework.cloud</groupId> <groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-client</artifactId> <artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
</dependency> </dependency>-->
<dependency> <dependency>
<groupId>org.springframework.boot</groupId> <groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId> <artifactId>spring-boot-starter-actuator</artifactId>
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.typroject</groupId> <groupId>org.typroject</groupId>
<artifactId>tyboot-core-foundation</artifactId> <artifactId>tyboot-core-foundation</artifactId>
<version>${tyboot-version}</version> <version>${tyboot-version}</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.typroject</groupId> <groupId>org.typroject</groupId>
<artifactId>tyboot-core-restful</artifactId> <artifactId>tyboot-core-restful</artifactId>
<version>${tyboot-version}</version> <version>${tyboot-version}</version>
<exclusions> <exclusions>
<exclusion> <exclusion>
<groupId>org.typroject</groupId> <groupId>org.typroject</groupId>
<artifactId>*</artifactId> <artifactId>*</artifactId>
</exclusion> </exclusion>
</exclusions> <exclusion>
</dependency> <groupId>org.bouncycastle</groupId>
<dependency> <artifactId>bcprov-jdk16</artifactId>
<groupId>org.typroject</groupId> </exclusion>
<artifactId>tyboot-core-auth</artifactId> </exclusions>
<version>${tyboot-version}</version> </dependency>
<exclusions> <dependency>
<exclusion> <groupId>org.typroject</groupId>
<groupId>org.typroject</groupId> <artifactId>tyboot-core-auth</artifactId>
<artifactId>*</artifactId> <version>${tyboot-version}</version>
</exclusion> <exclusions>
</exclusions> <exclusion>
</dependency> <groupId>org.typroject</groupId>
<dependency> <artifactId>*</artifactId>
<groupId>org.typroject</groupId> </exclusion>
<artifactId>tyboot-component-emq</artifactId> </exclusions>
<version>${tyboot-version}</version> </dependency>
</dependency> <dependency>
<!-- <groupId>org.typroject</groupId>
<dependency> <artifactId>tyboot-component-emq</artifactId>
<groupId>org.typroject</groupId> <version>${tyboot-version}</version>
<artifactId>tyboot-component-event</artifactId> </dependency>
<version>${tyboot-version}</version> <!--
<exclusions> <dependency>
<exclusion> <groupId>org.typroject</groupId>
<groupId>org.typroject</groupId> <artifactId>tyboot-component-event</artifactId>
<artifactId>*</artifactId> <version>${tyboot-version}</version>
</exclusion> <exclusions>
</exclusions> <exclusion>
</dependency> <groupId>org.typroject</groupId>
--> <artifactId>*</artifactId>
</exclusion>
</exclusions>
</dependency>
-->
<dependency> <dependency>
<groupId>org.typroject</groupId> <groupId>org.typroject</groupId>
<artifactId>tyboot-component-opendata</artifactId> <artifactId>tyboot-component-opendata</artifactId>
......
...@@ -24,36 +24,41 @@ ...@@ -24,36 +24,41 @@
<artifactId>taos-jdbcdriver</artifactId> <artifactId>taos-jdbcdriver</artifactId>
<version>3.2.4</version> <version>3.2.4</version>
</dependency> </dependency>
<!-- <dependency>
<groupId>org.bouncycastle</groupId>
<artifactId>bcprov-jdk15on</artifactId>
<version>1.70</version>
</dependency>
<dependency>
<groupId>org.bouncycastle</groupId>
<artifactId>bcpkix-jdk15on</artifactId>
<version>1.70</version>
</dependency>-->
<dependency> <dependency>
<groupId>org.bouncycastle</groupId> <groupId>org.bouncycastle</groupId>
<artifactId>bcprov-jdk15on</artifactId> <artifactId>bcprov-jdk16</artifactId>
<version>1.70</version> <!-- 请根据需要选择最新版本 --> <version>1.46</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.bouncycastle</groupId> <groupId>org.springframework</groupId>
<artifactId>bcpkix-jdk15on</artifactId> <artifactId>spring-mock</artifactId>
<version>1.70</version> <version>2.0.8</version>
</dependency> <scope>compile</scope>
<dependency> </dependency>
<groupId>org.springframework</groupId> </dependencies>
<artifactId>spring-mock</artifactId>
<version>2.0.8</version>
<scope>compile</scope>
</dependency>
</dependencies>
<dependencyManagement> <!-- <dependencyManagement>
<dependencies> <dependencies>
<dependency> <dependency>
<groupId>org.bouncycastle</groupId> <groupId>org.bouncycastle</groupId>
<artifactId>bcprov-jdk15on</artifactId> <artifactId>bcprov-jdk15on</artifactId>
<version>1.70</version> <version>1.70</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.bouncycastle</groupId> <groupId>org.bouncycastle</groupId>
<artifactId>bcpkix-jdk15on</artifactId> <artifactId>bcpkix-jdk15on</artifactId>
<version>1.70</version> <version>1.70</version>
</dependency> </dependency>
</dependencies> </dependencies>
</dependencyManagement> </dependencyManagement>-->
</project> </project>
package com.yeejoin.amos.boot.module.hygf.api.util; package com.yeejoin.amos.boot.module.hygf.api.util;
import java.io.FileInputStream;
import java.io.FileInputStream; import java.io.IOException;
import java.io.IOException; import java.io.InputStreamReader;
import java.io.InputStreamReader; import java.nio.charset.StandardCharsets;
import java.nio.charset.StandardCharsets; import java.security.KeyFactory;
import java.security.KeyFactory; import java.security.PrivateKey;
import java.security.PrivateKey; import java.security.PublicKey;
import java.security.PublicKey; import java.security.Signature;
import java.security.Signature; import java.security.cert.CertificateFactory;
import java.security.cert.CertificateFactory; import java.security.cert.X509Certificate;
import java.security.cert.X509Certificate; import java.security.interfaces.RSAPublicKey;
import java.security.interfaces.RSAPublicKey; import java.security.spec.PKCS8EncodedKeySpec;
import java.security.spec.PKCS8EncodedKeySpec; import java.security.spec.X509EncodedKeySpec;
import java.security.spec.X509EncodedKeySpec;
import org.apache.commons.codec.binary.Base64;
import org.apache.commons.codec.binary.Base64; import org.bouncycastle.asn1.DERNull;
import org.bouncycastle.asn1.DERNull; import org.bouncycastle.asn1.pkcs.PKCSObjectIdentifiers;
import org.bouncycastle.asn1.pkcs.PKCSObjectIdentifiers; import org.bouncycastle.asn1.pkcs.PrivateKeyInfo;
import org.bouncycastle.asn1.pkcs.PrivateKeyInfo; import org.bouncycastle.asn1.pkcs.RSAPrivateKeyStructure;
import org.bouncycastle.asn1.pkcs.RSAPrivateKey; import org.bouncycastle.asn1.x509.AlgorithmIdentifier;
import org.bouncycastle.asn1.x509.AlgorithmIdentifier; import org.bouncycastle.util.io.pem.PemObject;
import org.bouncycastle.util.io.pem.PemObject; import org.bouncycastle.util.io.pem.PemReader;
import org.bouncycastle.util.io.pem.PemReader; import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.ClassPathResource;
/** /**
* SHA256WithRSA签名、验签工具 * SHA256WithRSA签名、验签工具
...@@ -74,10 +73,9 @@ public class RSASignUtils { ...@@ -74,10 +73,9 @@ public class RSASignUtils {
} }
private static byte[] convertPKCS1ToPKCS8(byte[] pkcs1Bytes) throws Exception { private static byte[] convertPKCS1ToPKCS8(byte[] pkcs1Bytes) throws Exception {
// 使用 BouncyCastle 库解析 PKCS#1 格式的私钥 // 使用 BouncyCastle 库解析 PKCS#1 格式的私钥
RSAPrivateKey pkcs1PrivKey = RSAPrivateKey.getInstance(pkcs1Bytes); RSAPrivateKeyStructure pkcs1PrivKey = RSAPrivateKeyStructure.getInstance(pkcs1Bytes);
// 构建 AlgorithmIdentifier,指定了 rsaEncryption OID 和空参数 // 构建 AlgorithmIdentifier,指定了 rsaEncryption OID 和空参数
AlgorithmIdentifier algId = new AlgorithmIdentifier( AlgorithmIdentifier algId = new AlgorithmIdentifier(
...@@ -86,7 +84,7 @@ public class RSASignUtils { ...@@ -86,7 +84,7 @@ public class RSASignUtils {
); );
// 构建 PKCS#8 格式的私钥信息 // 构建 PKCS#8 格式的私钥信息
PrivateKeyInfo pkcs8PrivKeyInfo = new PrivateKeyInfo(algId, pkcs1PrivKey.toASN1Primitive()); PrivateKeyInfo pkcs8PrivKeyInfo = new PrivateKeyInfo(algId, pkcs1PrivKey.toASN1Object());
// 返回 PKCS#8 格式的编码字节数组 // 返回 PKCS#8 格式的编码字节数组
return pkcs8PrivKeyInfo.getEncoded(); return pkcs8PrivKeyInfo.getEncoded();
...@@ -123,7 +121,7 @@ public class RSASignUtils { ...@@ -123,7 +121,7 @@ public class RSASignUtils {
byte[] signbyte = (signBytes); byte[] signbyte = (signBytes);
return signatureTool.verify(signbyte); return signatureTool.verify(signbyte);
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
} }
return false; return false;
} }
...@@ -141,6 +139,7 @@ public class RSASignUtils { ...@@ -141,6 +139,7 @@ public class RSASignUtils {
} }
return false; return false;
} }
/** /**
* 加载 pkcs8 格式私钥 * 加载 pkcs8 格式私钥
* *
...@@ -210,11 +209,12 @@ public class RSASignUtils { ...@@ -210,11 +209,12 @@ public class RSASignUtils {
throw new Exception("Unexpected error while loading private key from file: " + path, e); throw new Exception("Unexpected error while loading private key from file: " + path, e);
} }
} }
/** /**
* 从文件加载 PKCS8 格式的 RSA 公钥 * 从文件加载 PKCS8 格式的 RSA 公钥
*/ */
public static RSAPublicKey readPublicKeyFromFile(String path) throws Exception { public static RSAPublicKey readPublicKeyFromFile(String path) throws Exception {
String publicKeyPEM ="-----BEGIN PUBLIC KEY-----\n" + String publicKeyPEM = "-----BEGIN PUBLIC KEY-----\n" +
"MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCwFgHD4kzEVPdOj03ctKM7KV+1\n" + "MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCwFgHD4kzEVPdOj03ctKM7KV+1\n" +
"6bWZ5BMNgvEeuEQwfQYkRVwI9HFOGkwNTMn5hiJXHnlXYCX+zp5r6R52MY0O7BsT\n" + "6bWZ5BMNgvEeuEQwfQYkRVwI9HFOGkwNTMn5hiJXHnlXYCX+zp5r6R52MY0O7BsT\n" +
"CLT7aHaxsANsvI9ABGx3OaTVlPB59M6GPbJh0uXvio0m1r/lTW3Z60RU6Q3oid/r\n" + "CLT7aHaxsANsvI9ABGx3OaTVlPB59M6GPbJh0uXvio0m1r/lTW3Z60RU6Q3oid/r\n" +
...@@ -238,9 +238,8 @@ public class RSASignUtils { ...@@ -238,9 +238,8 @@ public class RSASignUtils {
// RSASignUtils .loadPrivateKey("/Users/cyzx-mengxr/Downloads/private.pem"))); // RSASignUtils .loadPrivateKey("/Users/cyzx-mengxr/Downloads/private.pem")));
//String signSrc = RSAUtil.byte2Hex(FileUtils.toByteArray("/Users/cyzx-mengxr/Downloads/00008_0202202280000000579_0200003309088104357_001_20220930_acc_1_1.sign"));
//String signSrc = RSAUtil.byte2Hex(FileUtils.toByteArray("/Users/cyzx-mengxr/Downloads/00008_0202202280000000579_0200003309088104357_001_20220930_acc_1_1.sign")); //String signSrc = RSAUtil(FileUtils.toByteArray("/Users/cyzx-mengxr/Downloads/00008_0202202280000000579_0200003309088104357_001_20220930_acc_1_1.sign"));
//String signSrc = RSAUtil(FileUtils.toByteArray("/Users/cyzx-mengxr/Downloads/00008_0202202280000000579_0200003309088104357_001_20220930_acc_1_1.sign"));
/*验证网关文件*/ /*验证网关文件*/
// System.out.println( RSASignUtils.checkSignWithBytes( // System.out.println( RSASignUtils.checkSignWithBytes(
......
...@@ -24,18 +24,12 @@ ...@@ -24,18 +24,12 @@
<!-- <groupId>com.amosframework.boot</groupId>--> <!-- <groupId>com.amosframework.boot</groupId>-->
<!-- <artifactId>amos-boot-module-common-biz</artifactId>--> <!-- <artifactId>amos-boot-module-common-biz</artifactId>-->
<!-- <version>${amos-biz-boot.version}</version>--> <!-- <version>${amos-biz-boot.version}</version>-->
<!-- </dependency>--> <!-- </dependency>
<dependency> <dependency>
<groupId>org.apache.directory.studio</groupId> <groupId>org.apache.directory.studio</groupId>
<artifactId>org.apache.commons.codec</artifactId> <artifactId>org.apache.commons.codec</artifactId>
<version>1.8</version> <version>1.8</version>
</dependency> </dependency>-->
<!-- https://mvnrepository.com/artifact/org.bouncycastle/bcprov-jdk15on -->
<dependency>
<groupId>org.bouncycastle</groupId>
<artifactId>bcprov-jdk15on</artifactId>
<version>1.70</version>
</dependency>
<dependency> <dependency>
<groupId>org.typroject</groupId> <groupId>org.typroject</groupId>
<artifactId>tyboot-component-emq</artifactId> <artifactId>tyboot-component-emq</artifactId>
...@@ -128,6 +122,12 @@ ...@@ -128,6 +122,12 @@
</dependency> </dependency>
<dependency> <dependency>
<groupId>com.icbc.tool</groupId>
<artifactId>SM2</artifactId>
<version>1.0</version>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId> <groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml</artifactId> <artifactId>poi-ooxml</artifactId>
<version>4.1.2</version> <version>4.1.2</version>
......
package com.yeejoin.amos.boot.module.hygf.biz.service.impl; package com.yeejoin.amos.boot.module.hygf.biz.service.impl;
import java.io.IOException;
import java.io.PrintWriter; import java.io.PrintWriter;
import java.io.UnsupportedEncodingException; import java.io.UnsupportedEncodingException;
import java.net.URLDecoder; import java.net.URLDecoder;
...@@ -28,6 +29,8 @@ import javax.servlet.http.HttpServletResponse; ...@@ -28,6 +29,8 @@ import javax.servlet.http.HttpServletResponse;
import cn.hutool.core.bean.BeanUtil; import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.collection.CollectionUtil; import cn.hutool.core.collection.CollectionUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.csii.pp.icbc.util.SM4Utils;
import com.csii.pp.icbc.util.UtilIcbc;
import com.github.pagehelper.PageHelper; import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo; import com.github.pagehelper.PageInfo;
import com.icbc.api.request.*; import com.icbc.api.request.*;
...@@ -37,6 +40,7 @@ import com.yeejoin.amos.boot.module.hygf.api.dto.*; ...@@ -37,6 +40,7 @@ import com.yeejoin.amos.boot.module.hygf.api.dto.*;
import com.yeejoin.amos.boot.module.hygf.api.entity.PowerStationEngineeringInfo; import com.yeejoin.amos.boot.module.hygf.api.entity.PowerStationEngineeringInfo;
import com.yeejoin.amos.boot.module.hygf.api.mapper.HouseholdContractMapper; import com.yeejoin.amos.boot.module.hygf.api.mapper.HouseholdContractMapper;
import com.yeejoin.amos.boot.module.hygf.api.mapper.PowerStationEngineeringInfoMapper; import com.yeejoin.amos.boot.module.hygf.api.mapper.PowerStationEngineeringInfoMapper;
import com.yeejoin.amos.boot.module.hygf.biz.config.SM2Utils;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
...@@ -108,6 +112,10 @@ public class HygfIcbcServiceImpl extends BaseService<HygfIcbcRecordDTO, HygfIcbc ...@@ -108,6 +112,10 @@ public class HygfIcbcServiceImpl extends BaseService<HygfIcbcRecordDTO, HygfIcbc
private String OUT_VENDOR_ID; private String OUT_VENDOR_ID;
@Value("${hygf.icbc.projectId}") @Value("${hygf.icbc.projectId}")
private String PROJECT_ID; private String PROJECT_ID;
@Value("${hygf.icbc.sm2PublicKey}")
private String SM2_PUBLIC_KEY;
@Value("${hygf.icbc.sm2PrivateKey}")
private String SM2_PRIVATE_KEY;
/** /**
* 协议总限额 * 协议总限额
*/ */
...@@ -697,16 +705,16 @@ public class HygfIcbcServiceImpl extends BaseService<HygfIcbcRecordDTO, HygfIcbc ...@@ -697,16 +705,16 @@ public class HygfIcbcServiceImpl extends BaseService<HygfIcbcRecordDTO, HygfIcbc
} }
public Object signVerifyCode(String phone, String mediumId) { public Object signVerifyCode(String phone, String mediumId) {
// PeasantHousehold peasantHousehold=peasantHouseholdService PeasantHousehold peasantHousehold=peasantHouseholdService
// .getOne(new LambdaQueryWrapper<PeasantHousehold>().eq(PeasantHousehold::getTelephone,phone).last("LIMIT 1")); .getOne(new LambdaQueryWrapper<PeasantHousehold>().eq(PeasantHousehold::getTelephone,phone).last("LIMIT 1"));
// if(peasantHousehold==null) if(peasantHousehold==null)
// { {
// return "农户不存在"; return "农户不存在";
// } }
PeasantHousehold peasantHousehold = new PeasantHousehold(); // PeasantHousehold peasantHousehold = new PeasantHousehold();
peasantHousehold.setAmosUserId("890728"); // peasantHousehold.setAmosUserId("890728");
peasantHousehold.setOwnersName("吴江"); // peasantHousehold.setOwnersName("吴江");
peasantHousehold.setIdCard("61010319890728203X"); // peasantHousehold.setIdCard("61010319890728203X");
String apiUrl = serviceUrl + "/api/jft/api/user/entrust/send/verify/code/V1"; String apiUrl = serviceUrl + "/api/jft/api/user/entrust/send/verify/code/V1";
DefaultIcbcClient client = new DefaultIcbcClient(APP_ID, IcbcConstants.SIGN_TYPE_RSA2, MY_PRIVATE_KEY, DefaultIcbcClient client = new DefaultIcbcClient(APP_ID, IcbcConstants.SIGN_TYPE_RSA2, MY_PRIVATE_KEY,
IcbcConstants.CHARSET_UTF8, IcbcConstants.FORMAT_JSON, APIGW_PUBLIC_KEY, IcbcConstants.ENCRYPT_TYPE_AES, IcbcConstants.CHARSET_UTF8, IcbcConstants.FORMAT_JSON, APIGW_PUBLIC_KEY, IcbcConstants.ENCRYPT_TYPE_AES,
...@@ -754,16 +762,16 @@ public class HygfIcbcServiceImpl extends BaseService<HygfIcbcRecordDTO, HygfIcbc ...@@ -754,16 +762,16 @@ public class HygfIcbcServiceImpl extends BaseService<HygfIcbcRecordDTO, HygfIcbc
} }
public Object signProtocol(HygfIcbcSignProtocolDTO hygfIcbcSignProtocolDTO) { public Object signProtocol(HygfIcbcSignProtocolDTO hygfIcbcSignProtocolDTO) {
// PeasantHousehold peasantHousehold=peasantHouseholdService PeasantHousehold peasantHousehold=peasantHouseholdService
// .getOne(new LambdaQueryWrapper<PeasantHousehold>().eq(PeasantHousehold::getTelephone,hygfIcbcSignProtocolDTO.getPhone()).last("LIMIT 1")); .getOne(new LambdaQueryWrapper<PeasantHousehold>().eq(PeasantHousehold::getTelephone,hygfIcbcSignProtocolDTO.getPhone()).last("LIMIT 1"));
// if(peasantHousehold==null) if(peasantHousehold==null)
// { {
// return "农户不存在"; return "农户不存在";
// } }
PeasantHousehold peasantHousehold = new PeasantHousehold(); // PeasantHousehold peasantHousehold = new PeasantHousehold();
peasantHousehold.setAmosUserId("890728"); // peasantHousehold.setAmosUserId("890728");
peasantHousehold.setOwnersName("吴江"); // peasantHousehold.setOwnersName("吴江");
peasantHousehold.setIdCard("61010319890728203X"); // peasantHousehold.setIdCard("61010319890728203X");
DefaultIcbcClient client = new DefaultIcbcClient(APP_ID, IcbcConstants.SIGN_TYPE_RSA2, MY_PRIVATE_KEY, DefaultIcbcClient client = new DefaultIcbcClient(APP_ID, IcbcConstants.SIGN_TYPE_RSA2, MY_PRIVATE_KEY,
IcbcConstants.CHARSET_UTF8, IcbcConstants.FORMAT_JSON, APIGW_PUBLIC_KEY, IcbcConstants.ENCRYPT_TYPE_AES, IcbcConstants.CHARSET_UTF8, IcbcConstants.FORMAT_JSON, APIGW_PUBLIC_KEY, IcbcConstants.ENCRYPT_TYPE_AES,
AES_Key, "", ""); AES_Key, "", "");
...@@ -921,12 +929,28 @@ public class HygfIcbcServiceImpl extends BaseService<HygfIcbcRecordDTO, HygfIcbc ...@@ -921,12 +929,28 @@ public class HygfIcbcServiceImpl extends BaseService<HygfIcbcRecordDTO, HygfIcbc
bizContent.setCorpSerno(String.valueOf(System.currentTimeMillis()));//合作方交易单号 bizContent.setCorpSerno(String.valueOf(System.currentTimeMillis()));//合作方交易单号
bizContent.setCorpDate(formattedDate);//合作方工作日期 bizContent.setCorpDate(formattedDate);//合作方工作日期
bizContent.setOutServiceCode("querybalance");//外部服务代码 bizContent.setOutServiceCode("querybalance");//外部服务代码
bizContent.setMediumId(mediumId);//工行联名卡号 //String encodedString = Base64.getEncoder().encodeToString(mediumId.getBytes());
bizContent.setCcy(1);//市种 //生成sm4密钥
//bizContent.setSecretKey("h8zujhDntpKRohwFmGXcnXygNjJHRObyUVG3183u0dXI2fRgCXeDED9z0w5d02JucVy7vZ190d7CSUxI2/sVon6dPklVoaquVElgKRUPlr6D/cqLu25K7h]3Pt/u0nx4gF/ykm0/IB2gs0rs/sp0Zw=="); String origSecretKey = UtilIcbc.getNonceStr(16);
String secretKey = UtilIcbc.getHexString(origSecretKey.getBytes());
SM4Utils.secretKey = secretKey;
SM4Utils.hexString = true;
SM4Utils.iv = "00000000000000000000000000000000";
//生成sm2加密后的sm4公钥
String sm4SecretKey = null;
try {
sm4SecretKey = SM2Utils.encrypt(UtilIcbc.hexToByte(SM2_PUBLIC_KEY), origSecretKey.getBytes());
} catch (IOException e) {
throw new RuntimeException(e);
}
//涉密信息如身份证号,姓名,卡号都需要用sm4密钥进行加密
bizContent.setMediumId(SM4Utils.encryptData_CBC(mediumId)); //工行联名卡号
bizContent.setCcy(1); //币种,1
bizContent.setSecretKey(sm4SecretKey); // sm4对称密钥(对敏感信息加密时必送)
request.setBizContent(bizContent); request.setBizContent(bizContent);
SettlementAccountBalanceQueryResponseV1 response = null; SettlementAccountBalanceQueryResponseV1 response = null;
try { try {
log.info("工行卡查询余额, 入参 => {}", JSON.toJSONString(request));
response = client.execute(request, "msgId"); response = client.execute(request, "msgId");
if (response.isSuccess() && response.getReturnCode() == 0) { if (response.isSuccess() && response.getReturnCode() == 0) {
//业务成功处理 //业务成功处理
......
...@@ -3,7 +3,6 @@ package com.yeejoin.amos.boot.module.hygf.biz.service.impl; ...@@ -3,7 +3,6 @@ package com.yeejoin.amos.boot.module.hygf.biz.service.impl;
import cn.hutool.core.collection.CollectionUtil; import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.map.MapBuilder; import cn.hutool.core.map.MapBuilder;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.sun.org.apache.bcel.internal.generic.SWITCH;
import com.yeejoin.amos.boot.biz.common.utils.DateUtils; import com.yeejoin.amos.boot.biz.common.utils.DateUtils;
import com.yeejoin.amos.boot.module.hygf.api.Enum.CommonEnum; import com.yeejoin.amos.boot.module.hygf.api.Enum.CommonEnum;
import com.yeejoin.amos.boot.module.hygf.api.Enum.StatisicsHomePageEnum; import com.yeejoin.amos.boot.module.hygf.api.Enum.StatisicsHomePageEnum;
......
...@@ -272,6 +272,9 @@ hygf.icbc.camsPublicKey=655CE8706E6ED9A30B92E57D8D645ADDE8C541C27C5C5AFD529C610C ...@@ -272,6 +272,9 @@ hygf.icbc.camsPublicKey=655CE8706E6ED9A30B92E57D8D645ADDE8C541C27C5C5AFD529C610C
hygf.icbc.apigwPublicKey=MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCMpjaWjngB4E3ATh+G1DVAmQnIpiPEFAEDqRfNGAVvvH35yDetqewKi0l7OEceTMN1C6NPym3zStvSoQayjYV+eIcZERkx31KhtFu9clZKgRTyPjdKMIth/wBtPKjL/5+PYalLdomM4ONthrPgnkN4x4R0+D4+EBpXo8gNiAFsNwIDAQAB hygf.icbc.apigwPublicKey=MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCMpjaWjngB4E3ATh+G1DVAmQnIpiPEFAEDqRfNGAVvvH35yDetqewKi0l7OEceTMN1C6NPym3zStvSoQayjYV+eIcZERkx31KhtFu9clZKgRTyPjdKMIth/wBtPKjL/5+PYalLdomM4ONthrPgnkN4x4R0+D4+EBpXo8gNiAFsNwIDAQAB
hygf.icbc.outVendorId=gxjr hygf.icbc.outVendorId=gxjr
hygf.icbc.projectId=PJ140014023565102203 hygf.icbc.projectId=PJ140014023565102203
hygf.icbc.sm2PublicKey=04724755085cda47d161e4e1db0b4699521dcc0411fd34957457e9175b193ae6bf339e4c7a27e96d448f59073130c80efe1c6c0722c0f8c996567b31ead9f0f06e
hygf.icbc.sm2PrivateKey=807e5dcea2bb31f7846aa2bcc5211ed5903bfb718f4817abab3590058a71a915
icbc.Withhold.projectId=PJ140014023565102203 icbc.Withhold.projectId=PJ140014023565102203
icbc.Withhold.corpCis=211590000183323 icbc.Withhold.corpCis=211590000183323
......
...@@ -48,6 +48,7 @@ ...@@ -48,6 +48,7 @@
<artifactId>hutool-all</artifactId> <artifactId>hutool-all</artifactId>
<version>5.7.22</version> <version>5.7.22</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.bouncycastle</groupId> <groupId>org.bouncycastle</groupId>
<artifactId>bcprov-jdk15to18</artifactId> <artifactId>bcprov-jdk15to18</artifactId>
......
...@@ -42,6 +42,16 @@ ...@@ -42,6 +42,16 @@
<dependency> <dependency>
<groupId>org.springframework.cloud</groupId> <groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-server</artifactId> <artifactId>spring-cloud-starter-netflix-eureka-server</artifactId>
<exclusions>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-logging</artifactId>
</exclusion>
<exclusion>
<groupId>org.bouncycastle</groupId>
<artifactId>bcpkix-jdk15on</artifactId>
</exclusion>
</exclusions>
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.springframework.boot</groupId> <groupId>org.springframework.boot</groupId>
...@@ -319,7 +329,6 @@ ...@@ -319,7 +329,6 @@
<name>thirdparty</name> <name>thirdparty</name>
<url>http://47.92.103.240:8081/nexus/content/repositories/thirdparty/</url> <url>http://47.92.103.240:8081/nexus/content/repositories/thirdparty/</url>
</repository> </repository>
</repositories> </repositories>
<distributionManagement> <distributionManagement>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment