Compare commits
13 Commits
dev-V11.03
...
dev-sge
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
b5968c5245 | ||
|
|
73c315f714 | ||
|
|
b74443f38b | ||
|
|
b2d5103176 | ||
|
|
d34d5ff8e0 | ||
| c7324ba414 | |||
| 041f992992 | |||
| 22b7929e40 | |||
| 954e5fb637 | |||
| 3abf5021a3 | |||
| dc450dcdb5 | |||
| aacd927fbf | |||
| e18cfab77d |
1
.gitignore
vendored
1
.gitignore
vendored
@ -11,3 +11,4 @@
|
|||||||
/.DS_Store
|
/.DS_Store
|
||||||
src/test/java/com/sunyard/sydapi/sample/*.*
|
src/test/java/com/sunyard/sydapi/sample/*.*
|
||||||
*.p7
|
*.p7
|
||||||
|
/pack/
|
||||||
|
|||||||
1
doc/.gitignore
vendored
Normal file
1
doc/.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
~$*
|
||||||
73
kit.json
Normal file
73
kit.json
Normal file
@ -0,0 +1,73 @@
|
|||||||
|
{
|
||||||
|
"vars": {
|
||||||
|
"version": "%project.git_branch_version%",
|
||||||
|
"out_path": "./pack",
|
||||||
|
"target_f1": "./target/sydapi4j-jar-with-dependencies.jar",
|
||||||
|
"target_t1": "%out_path%/sydapi4j-jar-with-dependencies.jar",
|
||||||
|
"target_f2": "./target/sydapi4j.jar",
|
||||||
|
"target_t2": "%out_path%/sydapi4j.jar"
|
||||||
|
},
|
||||||
|
"clear": [
|
||||||
|
{
|
||||||
|
"func": "rmdir",
|
||||||
|
"path": "%out_path%"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"init": [
|
||||||
|
{
|
||||||
|
"func": "mkdir",
|
||||||
|
"path": "%out_path%"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"func": "mkdir",
|
||||||
|
"path": "%out_path%/jar"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"func": "mkdir",
|
||||||
|
"path": "%out_path%/jar/dependences"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"func": "mkdir",
|
||||||
|
"path": "%out_path%/doc"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"dependencies": [{
|
||||||
|
"func" : "pom",
|
||||||
|
"xml" : "%out_path%/jar"
|
||||||
|
}, {
|
||||||
|
"shell" : "mvn dependency:copy-dependencies -DincludeScope=runtime -DoutputDirectory=%out_path%/jar/dependences",
|
||||||
|
"check": "BUILD SUCCESS"
|
||||||
|
}],
|
||||||
|
"gen" : [{
|
||||||
|
"shell" : "dproto"
|
||||||
|
}],
|
||||||
|
"build": [
|
||||||
|
{
|
||||||
|
"cmd" : "init"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"shell": "mvn package -DskipTests",
|
||||||
|
"check": "BUILD SUCCESS"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"func": "cp",
|
||||||
|
"from": "%target_f1%",
|
||||||
|
"to": "%target_t1%"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"func": "cp",
|
||||||
|
"from": "%target_f2%",
|
||||||
|
"to": "%target_t2%"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"func": "zip",
|
||||||
|
"from": "%out_path%",
|
||||||
|
"to": "%out_path%/sydapi-%version%.zip"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"func": "open",
|
||||||
|
"path": "%out_path%"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
|
||||||
|
}
|
||||||
164
pom.xml
164
pom.xml
@ -4,7 +4,7 @@
|
|||||||
|
|
||||||
<groupId>com.sunyard</groupId>
|
<groupId>com.sunyard</groupId>
|
||||||
<artifactId>sydapi4j</artifactId>
|
<artifactId>sydapi4j</artifactId>
|
||||||
<version>1.0.20220712</version>
|
<version>1.15.20250701</version>
|
||||||
<packaging>jar</packaging>
|
<packaging>jar</packaging>
|
||||||
|
|
||||||
<name>sydapi4j</name>
|
<name>sydapi4j</name>
|
||||||
@ -26,6 +26,16 @@
|
|||||||
<version>4.12</version>
|
<version>4.12</version>
|
||||||
<scope>test</scope>
|
<scope>test</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.apache.logging.log4j</groupId>
|
||||||
|
<artifactId>log4j-api</artifactId>
|
||||||
|
<version>2.17.0</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.apache.logging.log4j</groupId>
|
||||||
|
<artifactId>log4j-core</artifactId>
|
||||||
|
<version>2.17.0</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
<!-- <!– https://mvnrepository.com/artifact/org.apache.commons/commons-pool2 –>-->
|
<!-- <!– https://mvnrepository.com/artifact/org.apache.commons/commons-pool2 –>-->
|
||||||
<!-- <dependency>-->
|
<!-- <dependency>-->
|
||||||
@ -72,10 +82,14 @@
|
|||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.sunyard</groupId>
|
<groupId>com.sunyard</groupId>
|
||||||
<artifactId>proto</artifactId>
|
<artifactId>proto</artifactId>
|
||||||
<version>1.0-20220412</version>
|
<version>1.0-20220905</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.codehaus.groovy</groupId>
|
||||||
|
<artifactId>groovy</artifactId>
|
||||||
|
<version>2.4.15</version>
|
||||||
|
</dependency>
|
||||||
<!--<dependency>-->
|
<!--<dependency>-->
|
||||||
<!--<groupId>club.fullstack</groupId>-->
|
<!--<groupId>club.fullstack</groupId>-->
|
||||||
<!--<artifactId>serialize</artifactId>-->
|
<!--<artifactId>serialize</artifactId>-->
|
||||||
@ -138,73 +152,57 @@
|
|||||||
</dependencies>
|
</dependencies>
|
||||||
</plugin>
|
</plugin>
|
||||||
|
|
||||||
<plugin>
|
<!-- <plugin>-->
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
<!-- <groupId>org.apache.maven.plugins</groupId>-->
|
||||||
<artifactId>maven-javadoc-plugin</artifactId>
|
<!-- <artifactId>maven-javadoc-plugin</artifactId>-->
|
||||||
<version>3.1.1</version>
|
<!-- <version>3.1.1</version>-->
|
||||||
<configuration>
|
<!-- <configuration>-->
|
||||||
<reportOutputDirectory>./public/</reportOutputDirectory>
|
<!-- <reportOutputDirectory>./public/</reportOutputDirectory>-->
|
||||||
<destDir>html</destDir>
|
<!-- <destDir>html</destDir>-->
|
||||||
<additionalOptions>html5</additionalOptions>
|
<!-- <additionalOptions>html5</additionalOptions>-->
|
||||||
<excludePackageNames>com.sunyard.SydApi:com.sunyard.inf.*:com.sunyard.cert.*</excludePackageNames>
|
<!-- <excludePackageNames>com.sunyard.SydApi:com.sunyard.inf.*:com.sunyard.cert.*</excludePackageNames>-->
|
||||||
</configuration>
|
<!-- </configuration>-->
|
||||||
</plugin>
|
<!-- </plugin>-->
|
||||||
|
|
||||||
<plugin>
|
<!-- <plugin>-->
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
<!-- <groupId>org.apache.maven.plugins</groupId>-->
|
||||||
<artifactId>maven-source-plugin</artifactId>
|
<!-- <artifactId>maven-source-plugin</artifactId>-->
|
||||||
<version>2.4</version>
|
<!-- <version>2.4</version>-->
|
||||||
|
|
||||||
<!-- 进行package命令时就可以将源码同时进行打包 -->
|
<!-- <!– 进行package命令时就可以将源码同时进行打包 –>-->
|
||||||
<!-- 所以我们需要绑定source插件到我们default生命周期的package阶段 -->
|
<!-- <!– 所以我们需要绑定source插件到我们default生命周期的package阶段 –>-->
|
||||||
<executions>
|
<!-- <executions>-->
|
||||||
<execution>
|
<!-- <execution>-->
|
||||||
<!-- 定义一个阶段,这个阶段是package -->
|
<!-- <!– 定义一个阶段,这个阶段是package –>-->
|
||||||
<phase>package</phase>
|
<!-- <phase>package</phase>-->
|
||||||
<goals>
|
<!-- <goals>-->
|
||||||
<goal>jar-no-fork</goal>
|
<!-- <goal>jar-no-fork</goal>-->
|
||||||
</goals>
|
<!-- </goals>-->
|
||||||
</execution>
|
<!-- </execution>-->
|
||||||
</executions>
|
<!-- </executions>-->
|
||||||
</plugin>
|
<!-- </plugin>-->
|
||||||
|
|
||||||
|
<!-- <plugin>-->
|
||||||
|
<!-- <groupId>org.apache.maven.plugins</groupId>-->
|
||||||
<plugin>
|
<!-- <artifactId>maven-dependency-plugin</artifactId>-->
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
<!-- <configuration>-->
|
||||||
<artifactId>maven-jar-plugin</artifactId>
|
<!-- <includeScope>runtime</includeScope>-->
|
||||||
<configuration>
|
<!-- </configuration>-->
|
||||||
<archive>
|
<!-- <executions>-->
|
||||||
<manifest>
|
<!-- <execution>-->
|
||||||
<addClasspath>true</addClasspath>
|
<!-- <id>copy</id>-->
|
||||||
<classpathPrefix>lib/</classpathPrefix>
|
<!-- <phase>package</phase>-->
|
||||||
<mainClass>com.xxx.uploadFile</mainClass>
|
<!-- <goals>-->
|
||||||
</manifest>
|
<!-- <goal>copy-dependencies</goal>-->
|
||||||
</archive>
|
<!-- </goals>-->
|
||||||
</configuration>
|
<!-- <configuration>-->
|
||||||
</plugin>
|
<!-- <outputDirectory>-->
|
||||||
|
<!-- ${project.build.directory}/lib-->
|
||||||
<plugin>
|
<!-- </outputDirectory>-->
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
<!-- </configuration>-->
|
||||||
<artifactId>maven-dependency-plugin</artifactId>
|
<!-- </execution>-->
|
||||||
<configuration>
|
<!-- </executions>-->
|
||||||
<includeScope>runtime</includeScope>
|
<!-- </plugin>-->
|
||||||
</configuration>
|
|
||||||
<executions>
|
|
||||||
<execution>
|
|
||||||
<id>copy</id>
|
|
||||||
<phase>package</phase>
|
|
||||||
<goals>
|
|
||||||
<goal>copy-dependencies</goal>
|
|
||||||
</goals>
|
|
||||||
<configuration>
|
|
||||||
<outputDirectory>
|
|
||||||
${project.build.directory}/lib
|
|
||||||
</outputDirectory>
|
|
||||||
</configuration>
|
|
||||||
</execution>
|
|
||||||
</executions>
|
|
||||||
</plugin>
|
|
||||||
|
|
||||||
|
|
||||||
<plugin>
|
<plugin>
|
||||||
@ -228,38 +226,6 @@
|
|||||||
</execution>
|
</execution>
|
||||||
</executions>
|
</executions>
|
||||||
</plugin>
|
</plugin>
|
||||||
|
|
||||||
<!-- <plugin>-->
|
|
||||||
<!-- <groupId>org.jetbrains.kotlin</groupId>-->
|
|
||||||
<!-- <artifactId>kotlin-maven-plugin</artifactId>-->
|
|
||||||
<!-- <version>${kotlin.version}</version>-->
|
|
||||||
<!-- <executions>-->
|
|
||||||
<!-- <execution>-->
|
|
||||||
<!-- <id>compile</id>-->
|
|
||||||
<!-- <phase>compile</phase>-->
|
|
||||||
<!-- <goals>-->
|
|
||||||
<!-- <goal>compile</goal>-->
|
|
||||||
<!-- </goals>-->
|
|
||||||
<!-- <configuration>-->
|
|
||||||
<!-- <sourceDirs>-->
|
|
||||||
<!-- <source>src/main/java</source>-->
|
|
||||||
<!-- </sourceDirs>-->
|
|
||||||
<!-- </configuration>-->
|
|
||||||
<!-- </execution>-->
|
|
||||||
<!-- <execution>-->
|
|
||||||
<!-- <id>test-compile</id>-->
|
|
||||||
<!-- <phase>test-compile</phase>-->
|
|
||||||
<!-- <goals>-->
|
|
||||||
<!-- <goal>test-compile</goal>-->
|
|
||||||
<!-- </goals>-->
|
|
||||||
<!-- </execution>-->
|
|
||||||
<!-- </executions>-->
|
|
||||||
<!-- <configuration>-->
|
|
||||||
<!-- <jvmTarget>1.6</jvmTarget>-->
|
|
||||||
<!-- </configuration>-->
|
|
||||||
<!-- </plugin>-->
|
|
||||||
|
|
||||||
|
|
||||||
</plugins>
|
</plugins>
|
||||||
<!-- 主资源目录 -->
|
<!-- 主资源目录 -->
|
||||||
<resources>
|
<resources>
|
||||||
|
|||||||
@ -81,6 +81,13 @@ public class SydApiException extends RuntimeException{
|
|||||||
|
|
||||||
case 40000:
|
case 40000:
|
||||||
this.msg = "输入的大数据处理异常";
|
this.msg = "输入的大数据处理异常";
|
||||||
|
break;
|
||||||
|
case 56300:
|
||||||
|
this.msg = "证书导入错误";
|
||||||
|
break;
|
||||||
|
case 56307:
|
||||||
|
this.msg = "证书删除错误";
|
||||||
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
this.msg = "未定义的错误";
|
this.msg = "未定义的错误";
|
||||||
@ -88,13 +95,23 @@ public class SydApiException extends RuntimeException{
|
|||||||
}
|
}
|
||||||
|
|
||||||
public SydApiException(int retCode) {
|
public SydApiException(int retCode) {
|
||||||
|
super("SydApiException(" + "code = "+String.format("%d", retCode) + ")" );
|
||||||
this.retCode = retCode;
|
this.retCode = retCode;
|
||||||
transMsg();
|
transMsg();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public SydApiException(String msg, int ret, Throwable e){
|
||||||
|
super("SydApiException(" +"code ="+ String.format(" %d", ret) + " : "+"msg ="+ (null == msg ? "未定义的错误" : msg) +")" , e);
|
||||||
|
this.retCode = ret;
|
||||||
|
if (null == msg || "".equals(msg)){
|
||||||
|
transMsg();
|
||||||
|
}else {
|
||||||
|
this.msg = msg;
|
||||||
|
}
|
||||||
|
}
|
||||||
public SydApiException(String msg, int ret){
|
public SydApiException(String msg, int ret){
|
||||||
this(ret);
|
super("SydApiException(" +"code ="+ String.format(" %d", ret) + " : "+"msg ="+ (null == msg ? "未定义的错误" : msg) +")" );
|
||||||
|
this.retCode = ret;
|
||||||
if (null == msg || "".equals(msg)){
|
if (null == msg || "".equals(msg)){
|
||||||
transMsg();
|
transMsg();
|
||||||
}else {
|
}else {
|
||||||
|
|||||||
@ -38,6 +38,14 @@ interface SydHashApi {
|
|||||||
*/
|
*/
|
||||||
byte[] SM3Hash(String publicKey, byte[] msg, int block, byte[] mac);
|
byte[] SM3Hash(String publicKey, byte[] msg, int block, byte[] mac);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 计算SM3散列值
|
||||||
|
* @param publicKey 公钥的 DER 编码 (03420004 开头)
|
||||||
|
* @param userId 用户ID
|
||||||
|
* @param msg 原始数据,二进制的消息块
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
byte[] SM3Hash(String publicKey, String userId, byte[] msg);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 输入对指定的原始数据和公钥,通过 SM3 算法计算数据的散列值。
|
* 输入对指定的原始数据和公钥,通过 SM3 算法计算数据的散列值。
|
||||||
@ -267,7 +275,7 @@ interface SydSYMApi {
|
|||||||
byte[] SYMEncryptData(int nAlg, String seesionKey, int fullmode, byte[] pINdata);
|
byte[] SYMEncryptData(int nAlg, String seesionKey, int fullmode, byte[] pINdata);
|
||||||
|
|
||||||
|
|
||||||
List<byte[]> SYMEncryptDecryptBatchData(int nAlg, String[] seesionKey, int fullmode, List<byte[]> pINdata);
|
// List<byte[]> SYMEncryptDecryptBatchData(int nAlg, String[] seesionKey, int fullmode, List<byte[]> pINdata);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 用输入的会话密钥,对指定报文数据进行加密处理。
|
* 用输入的会话密钥,对指定报文数据进行加密处理。
|
||||||
|
|||||||
5
src/main/java/com/sunyard/log/ILogFactory.java
Normal file
5
src/main/java/com/sunyard/log/ILogFactory.java
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
package com.sunyard.log;
|
||||||
|
|
||||||
|
public interface ILogFactory {
|
||||||
|
ILogger getLogger(Class var1);
|
||||||
|
}
|
||||||
13
src/main/java/com/sunyard/log/ILogger.java
Normal file
13
src/main/java/com/sunyard/log/ILogger.java
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
package com.sunyard.log;
|
||||||
|
|
||||||
|
public interface ILogger {
|
||||||
|
int getCurrentLogLevel();
|
||||||
|
|
||||||
|
void error(String var1, Object... var2);
|
||||||
|
|
||||||
|
void info(String var1, Object... var2);
|
||||||
|
|
||||||
|
void debug(String var1, Object... var2);
|
||||||
|
|
||||||
|
boolean isDebugEnabled();
|
||||||
|
}
|
||||||
101
src/main/java/com/sunyard/log/SydLogFactory.java
Normal file
101
src/main/java/com/sunyard/log/SydLogFactory.java
Normal file
@ -0,0 +1,101 @@
|
|||||||
|
//
|
||||||
|
// Source code recreated from a .class file by IntelliJ IDEA
|
||||||
|
// (powered by FernFlower decompiler)
|
||||||
|
//
|
||||||
|
|
||||||
|
package com.sunyard.log;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.FileOutputStream;
|
||||||
|
import java.text.SimpleDateFormat;
|
||||||
|
import java.util.Date;
|
||||||
|
import java.util.concurrent.ConcurrentLinkedQueue;
|
||||||
|
import java.util.concurrent.Executor;
|
||||||
|
import java.util.concurrent.Executors;
|
||||||
|
|
||||||
|
public class SydLogFactory implements ILogFactory {
|
||||||
|
private static SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
|
||||||
|
public static String pcLogPath = "./sydapi-logs/";
|
||||||
|
public static final String logName = "sydapi-log";
|
||||||
|
public static int iLogLevel = 0;
|
||||||
|
private static ConcurrentLinkedQueue<SydLogInfo> queue = new ConcurrentLinkedQueue();
|
||||||
|
public static boolean debug = false;
|
||||||
|
private static Executor executor = Executors.newSingleThreadExecutor();
|
||||||
|
|
||||||
|
static {
|
||||||
|
executor.execute(new Runnable() {
|
||||||
|
public void run() {
|
||||||
|
String logFileName = "";
|
||||||
|
FileOutputStream logFos = null;
|
||||||
|
|
||||||
|
while(true) {
|
||||||
|
while(true) {
|
||||||
|
while(true) {
|
||||||
|
try {
|
||||||
|
if (SydLogFactory.queue.isEmpty()) {
|
||||||
|
Thread.sleep(500L);
|
||||||
|
} else {
|
||||||
|
String mayLogFileName = String.format("%s_%s.log", "sydapi-log", SydLogFactory.format.format(new Date()));
|
||||||
|
if (!logFileName.equals(mayLogFileName)) {
|
||||||
|
logFileName = mayLogFileName;
|
||||||
|
if (logFos != null) {
|
||||||
|
logFos.flush();
|
||||||
|
logFos.close();
|
||||||
|
}
|
||||||
|
|
||||||
|
File folder = new File(SydLogFactory.pcLogPath);
|
||||||
|
if (!folder.exists()) {
|
||||||
|
folder.mkdirs();
|
||||||
|
}
|
||||||
|
|
||||||
|
File f = new File(SydLogFactory.pcLogPath, logFileName);
|
||||||
|
if (!f.exists()) {
|
||||||
|
f.createNewFile();
|
||||||
|
}
|
||||||
|
|
||||||
|
logFos = new FileOutputStream(f, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
while(!SydLogFactory.queue.isEmpty()) {
|
||||||
|
SydLogInfo info = (SydLogInfo)SydLogFactory.queue.poll();
|
||||||
|
logFos.write(String.format("[%d:%s <%s-%d>] %s\r\n", info.getLevel(), SydLogFactory.format.format(new Date(info.getDatatime())), info.getTname(), info.getTid(), info.getMsg()).getBytes());
|
||||||
|
}
|
||||||
|
|
||||||
|
logFos.flush();
|
||||||
|
}
|
||||||
|
} catch (Exception var9) {
|
||||||
|
Exception e = var9;
|
||||||
|
e.printStackTrace();
|
||||||
|
} finally {
|
||||||
|
SydLogFactory.closeFileOutputStream(logFos);
|
||||||
|
logFileName = "";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void closeFileOutputStream(FileOutputStream fos) {
|
||||||
|
if (fos != null) {
|
||||||
|
try {
|
||||||
|
fos.flush();
|
||||||
|
} catch (Exception var2) {
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
fos.close();
|
||||||
|
} catch (Exception var1) {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private SydLogFactory() {
|
||||||
|
}
|
||||||
|
|
||||||
|
public ILogger getLogger(Class cls) {
|
||||||
|
return new SydLogger(queue);
|
||||||
|
}
|
||||||
|
}
|
||||||
48
src/main/java/com/sunyard/log/SydLogInfo.java
Normal file
48
src/main/java/com/sunyard/log/SydLogInfo.java
Normal file
@ -0,0 +1,48 @@
|
|||||||
|
//
|
||||||
|
// Source code recreated from a .class file by IntelliJ IDEA
|
||||||
|
// (powered by FernFlower decompiler)
|
||||||
|
//
|
||||||
|
|
||||||
|
package com.sunyard.log;
|
||||||
|
|
||||||
|
public class SydLogInfo {
|
||||||
|
private int level;
|
||||||
|
private long datatime;
|
||||||
|
private String tname;
|
||||||
|
private long tid;
|
||||||
|
private String msg;
|
||||||
|
private Object[] objects;
|
||||||
|
|
||||||
|
public SydLogInfo(int level, String msg, Object[] objects) {
|
||||||
|
this.level = level;
|
||||||
|
this.msg = msg;
|
||||||
|
this.objects = objects;
|
||||||
|
this.datatime = System.currentTimeMillis();
|
||||||
|
this.tname = Thread.currentThread().getName();
|
||||||
|
this.tid = Thread.currentThread().getId();
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getLevel() {
|
||||||
|
return this.level;
|
||||||
|
}
|
||||||
|
|
||||||
|
public long getDatatime() {
|
||||||
|
return this.datatime;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getTname() {
|
||||||
|
return this.tname;
|
||||||
|
}
|
||||||
|
|
||||||
|
public long getTid() {
|
||||||
|
return this.tid;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getMsg() {
|
||||||
|
return this.msg;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Object[] getObjects() {
|
||||||
|
return this.objects;
|
||||||
|
}
|
||||||
|
}
|
||||||
47
src/main/java/com/sunyard/log/SydLogger.java
Normal file
47
src/main/java/com/sunyard/log/SydLogger.java
Normal file
@ -0,0 +1,47 @@
|
|||||||
|
//
|
||||||
|
// Source code recreated from a .class file by IntelliJ IDEA
|
||||||
|
// (powered by FernFlower decompiler)
|
||||||
|
//
|
||||||
|
|
||||||
|
package com.sunyard.log;
|
||||||
|
|
||||||
|
import java.util.concurrent.ConcurrentLinkedQueue;
|
||||||
|
|
||||||
|
public class SydLogger implements ILogger {
|
||||||
|
private ConcurrentLinkedQueue<SydLogInfo> queue;
|
||||||
|
|
||||||
|
SydLogger(ConcurrentLinkedQueue<SydLogInfo> queue) {
|
||||||
|
this.queue = queue;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void debug(String msg, Object... params) {
|
||||||
|
if (SydLogFactory.iLogLevel == 3) {
|
||||||
|
this.queue.add(new SydLogInfo(3, msg, params));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isDebugEnabled() {
|
||||||
|
return SydLogFactory.iLogLevel == 3;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void info(String msg, Object... params) {
|
||||||
|
if (SydLogFactory.iLogLevel >= 2) {
|
||||||
|
this.queue.add(new SydLogInfo(2, msg, params));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void error(String msg, Object... params) {
|
||||||
|
if (SydLogFactory.iLogLevel >= 1) {
|
||||||
|
this.queue.add(new SydLogInfo(1, msg, params));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getCurrentLogLevel() {
|
||||||
|
return SydLogFactory.iLogLevel;
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -6,11 +6,12 @@ import com.sunyard.SydApi;
|
|||||||
import com.sunyard.SydApiException;
|
import com.sunyard.SydApiException;
|
||||||
import com.sunyard.cert.X509;
|
import com.sunyard.cert.X509;
|
||||||
import com.sunyard.entity.Struct;
|
import com.sunyard.entity.Struct;
|
||||||
|
import com.sunyard.log.ILogFactory;
|
||||||
|
import com.sunyard.log.ILogger;
|
||||||
import com.sunyard.proto.Packet;
|
import com.sunyard.proto.Packet;
|
||||||
import com.sunyard.proto.PacketSection;
|
import com.sunyard.proto.PacketSection;
|
||||||
import com.sunyard.proto.Util;
|
import com.sunyard.proto.Util;
|
||||||
import com.sunyard.proto.section.SectionValue;
|
import com.sunyard.proto.section.SectionValue;
|
||||||
import com.sunyard.proto.value.Str;
|
|
||||||
import com.sunyard.trans.Alg;
|
import com.sunyard.trans.Alg;
|
||||||
import com.sunyard.trans.FullMode;
|
import com.sunyard.trans.FullMode;
|
||||||
import com.sunyard.trans.PacketSN;
|
import com.sunyard.trans.PacketSN;
|
||||||
@ -19,6 +20,7 @@ import com.sunyard.util.CoderUtil;
|
|||||||
import com.sunyard.util.FileUtil;
|
import com.sunyard.util.FileUtil;
|
||||||
import com.sunyard.util.MyUtil;
|
import com.sunyard.util.MyUtil;
|
||||||
import com.sunyard.util.SYMUtil;
|
import com.sunyard.util.SYMUtil;
|
||||||
|
import org.apache.logging.log4j.Logger;
|
||||||
import racal.sunyard.main.dto.*;
|
import racal.sunyard.main.dto.*;
|
||||||
import racal.sunyard.main.proto.*;
|
import racal.sunyard.main.proto.*;
|
||||||
|
|
||||||
@ -27,13 +29,23 @@ import java.net.InetSocketAddress;
|
|||||||
import java.net.Socket;
|
import java.net.Socket;
|
||||||
import java.net.SocketAddress;
|
import java.net.SocketAddress;
|
||||||
import java.net.SocketTimeoutException;
|
import java.net.SocketTimeoutException;
|
||||||
import java.nio.Buffer;
|
|
||||||
import java.nio.ByteBuffer;
|
import java.nio.ByteBuffer;
|
||||||
import java.nio.charset.Charset;
|
import java.nio.charset.Charset;
|
||||||
import java.text.SimpleDateFormat;
|
import java.text.SimpleDateFormat;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
|
||||||
public class SydApi4j implements SydApi {
|
public class SydApi4j implements SydApi {
|
||||||
|
private static ILogFactory logFactory = null;
|
||||||
|
private static ILogger logger = null;
|
||||||
|
|
||||||
|
// 数据包长度
|
||||||
|
private final int MaxDataLenEachPack = 4064;
|
||||||
|
|
||||||
|
// 批量数据包,单包数据长度
|
||||||
|
// 加密
|
||||||
|
private final int MaxDataLenEachBatchPackEn = 1024;
|
||||||
|
// 解密
|
||||||
|
private final int MaxDataLenEachBatchPackDe = 1040;
|
||||||
|
|
||||||
private static boolean debug = false;
|
private static boolean debug = false;
|
||||||
|
|
||||||
@ -44,6 +56,23 @@ public class SydApi4j implements SydApi {
|
|||||||
private static int port;
|
private static int port;
|
||||||
private static int timeout;
|
private static int timeout;
|
||||||
|
|
||||||
|
public static ILogFactory getLogFactory() {
|
||||||
|
return logFactory;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void setLogFactory(ILogFactory logFactory) {
|
||||||
|
SydApi4j.logFactory = logFactory;
|
||||||
|
logger = logFactory.getLogger(SydApi4j.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public static void setLogger(Logger log) {
|
||||||
|
SydApi4j.log = log;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static Logger log;
|
||||||
|
|
||||||
|
|
||||||
//初始化变量
|
//初始化变量
|
||||||
static {
|
static {
|
||||||
|
|
||||||
@ -1076,20 +1105,43 @@ public class SydApi4j implements SydApi {
|
|||||||
|
|
||||||
|
|
||||||
private static void println(Object i) {
|
private static void println(Object i) {
|
||||||
if (debug) {
|
if ( debug ) {
|
||||||
System.out.println(i);
|
System.out.println(i);
|
||||||
}
|
}
|
||||||
|
if ( null != log && log.isDebugEnabled()) {
|
||||||
|
log.debug("{}", i);
|
||||||
|
}
|
||||||
|
if ( null != logger && logger.isDebugEnabled()) {
|
||||||
|
logger.debug("{}", i);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void print(Object i) {
|
private static void print(Object i) {
|
||||||
if (debug) {
|
if (debug) {
|
||||||
System.out.print(i);
|
System.out.print(i);
|
||||||
}
|
}
|
||||||
|
if ( null != log && log.isDebugEnabled()) {
|
||||||
|
log.debug("{}", i);
|
||||||
|
}
|
||||||
|
if ( null != logger && logger.isDebugEnabled()) {
|
||||||
|
logger.debug("{}", i);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//gc回收
|
|
||||||
|
private static void printHex(byte[] data) {
|
||||||
|
if (debug) {
|
||||||
|
System.out.print(Util.bytes2HexString(data));
|
||||||
|
}
|
||||||
|
if ( null != log && log.isDebugEnabled()) {
|
||||||
|
log.debug("{}", Util.bytes2HexString(data));
|
||||||
|
}
|
||||||
|
if ( null != logger && logger.isDebugEnabled()) {
|
||||||
|
logger.debug("{}", Util.bytes2HexString(data));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// gc回收
|
||||||
@Override
|
@Override
|
||||||
protected void finalize() throws Throwable {
|
protected void finalize() throws Throwable {
|
||||||
super.finalize();
|
super.finalize();
|
||||||
@ -1116,6 +1168,7 @@ public class SydApi4j implements SydApi {
|
|||||||
try {
|
try {
|
||||||
s1.connect(address, timeout);
|
s1.connect(address, timeout);
|
||||||
socket = s1;
|
socket = s1;
|
||||||
|
socket.setTcpNoDelay(true);
|
||||||
socket.setSoTimeout(timeout);
|
socket.setSoTimeout(timeout);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
Socket s2 = new Socket();
|
Socket s2 = new Socket();
|
||||||
@ -1123,6 +1176,7 @@ public class SydApi4j implements SydApi {
|
|||||||
try {
|
try {
|
||||||
s2.connect(add2, timeout);
|
s2.connect(add2, timeout);
|
||||||
socket = s2;
|
socket = s2;
|
||||||
|
socket.setTcpNoDelay(true);
|
||||||
socket.setSoTimeout(timeout);
|
socket.setSoTimeout(timeout);
|
||||||
} catch (Exception e2) {
|
} catch (Exception e2) {
|
||||||
throw new SydApiException(-2);
|
throw new SydApiException(-2);
|
||||||
@ -1149,16 +1203,16 @@ public class SydApi4j implements SydApi {
|
|||||||
|
|
||||||
|
|
||||||
println("\n\n发送数据");
|
println("\n\n发送数据");
|
||||||
// print("原始数据: \t");
|
|
||||||
// println(Arrays.toString(buff));
|
|
||||||
print("HEX数据: \t");
|
print("HEX数据: \t");
|
||||||
println(Util.bytes2HexString(buff));
|
printHex(buff);
|
||||||
|
|
||||||
if (null != builder && builder.isUseEBCDMode()) {
|
if (null != builder && builder.isUseEBCDMode()) {
|
||||||
// 对十个字节之后的进行 EBCD 转码
|
// 对十个字节之后的进行 EBCD 转码
|
||||||
buff = CoderUtil.ASCIIToEBCDICFIX(buff, 10);
|
buff = CoderUtil.ASCIIToEBCDICFIX(buff, 10);
|
||||||
|
|
||||||
print("EBCD 数据: \t");
|
print("EBCD 数据: \t");
|
||||||
println(Util.bytes2HexString(buff));
|
printHex(buff);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
testSocket();
|
testSocket();
|
||||||
@ -1184,7 +1238,7 @@ public class SydApi4j implements SydApi {
|
|||||||
print("原始数据: \t");
|
print("原始数据: \t");
|
||||||
println(Arrays.toString(buff));
|
println(Arrays.toString(buff));
|
||||||
print("HEX数据: \t");
|
print("HEX数据: \t");
|
||||||
println(Util.bytes2HexString(buff));
|
printHex(buff);
|
||||||
|
|
||||||
testSocket();
|
testSocket();
|
||||||
|
|
||||||
@ -1218,58 +1272,62 @@ public class SydApi4j implements SydApi {
|
|||||||
|
|
||||||
private ByteBuffer read(Socket socket) throws IOException {
|
private ByteBuffer read(Socket socket) throws IOException {
|
||||||
InputStream is = socket.getInputStream();
|
InputStream is = socket.getInputStream();
|
||||||
int d;
|
|
||||||
int high = is.read();
|
|
||||||
int low = is.read();
|
|
||||||
int len = (high << 8) + low;
|
|
||||||
|
|
||||||
len += 2;
|
// 一次性读取前2个字节(长度字段)
|
||||||
|
byte[] lenBytes = new byte[2];
|
||||||
|
int bytesRead = is.read(lenBytes);
|
||||||
|
if (bytesRead != 2) {
|
||||||
|
throw new EOFException("Connection closed before reading length bytes");
|
||||||
|
}
|
||||||
|
|
||||||
|
int high = lenBytes[0] & 0xFF;
|
||||||
|
int low = lenBytes[1] & 0xFF;
|
||||||
|
int len = (high << 8) + low + 2; // 总长度 = 数据长度 + 2字节长度字段
|
||||||
|
|
||||||
|
if (debug) {
|
||||||
|
// 调试输出
|
||||||
print("H\t");
|
print("H\t");
|
||||||
println(Integer.toHexString(high));
|
println(Integer.toHexString(high));
|
||||||
print("L\t");
|
print("L\t");
|
||||||
println(Integer.toHexString(low));
|
println(Integer.toHexString(low));
|
||||||
print("Len\t");
|
print("Len\t");
|
||||||
println(len);
|
println(len);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 分配缓冲区并放入前2个字节
|
||||||
ByteBuffer bb = ByteBuffer.allocate(len);
|
ByteBuffer bb = ByteBuffer.allocate(len);
|
||||||
bb.put((byte) (high & 0xFF));
|
bb.put(lenBytes);
|
||||||
//println(String.format("%d %d %s",len, bb.position() -1, Util.bytes2HexString(new byte[]{(byte) (high & 0xFF)})));
|
|
||||||
|
|
||||||
bb.put((byte) (low & 0xFF));
|
// 读取剩余数据
|
||||||
//println(String.format("%d %d %s",len, bb.position() -1, Util.bytes2HexString(new byte[]{(byte) (low & 0xFF)})));
|
byte[] data = new byte[len - 2];
|
||||||
|
int totalRead = 0;
|
||||||
|
while (totalRead < data.length) {
|
||||||
while (true) {
|
bytesRead = is.read(data, totalRead, data.length - totalRead);
|
||||||
d = is.read();
|
if (bytesRead == -1) {
|
||||||
if (-1 == d) {
|
throw new EOFException("Connection closed before reading all data");
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
totalRead += bytesRead;
|
||||||
bb.put((byte) (d & 0xFF));
|
|
||||||
|
|
||||||
//println(String.format("%d %d %s",len, bb.position() -1, Util.bytes2HexString(new byte[]{(byte) (d & 0xFF)})));
|
|
||||||
|
|
||||||
if (bb.position() == len) {
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
bb.put(data);
|
||||||
|
|
||||||
|
|
||||||
if (null != builder && builder.isUseEBCDMode()) {
|
if (null != builder && builder.isUseEBCDMode()) {
|
||||||
|
if (debug) {
|
||||||
print("EBCD 数据: \t");
|
print("EBCD 数据: \t");
|
||||||
println(Util.bytes2HexString(bb.array()));
|
printHex(bb.array());
|
||||||
|
}
|
||||||
|
|
||||||
byte[] b = bb.array();
|
byte[] b = bb.array();
|
||||||
CoderUtil.EBCDICToASCIIFIX(b, 10);
|
CoderUtil.EBCDICToASCIIFIX(b, 10);
|
||||||
}
|
}
|
||||||
|
|
||||||
print("HEX数据: \t");
|
|
||||||
println(Util.bytes2HexString(bb.array()));
|
print("read HEX数据: \t");
|
||||||
|
printHex(bb.array());
|
||||||
|
|
||||||
return bb;
|
return bb;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 阻塞读取
|
* 阻塞读取
|
||||||
* 前两个字节是长度
|
* 前两个字节是长度
|
||||||
@ -1974,7 +2032,257 @@ public class SydApi4j implements SydApi {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public List<byte[]> SYMEncryptDecryptBatchData(int nAlg, String[] seesionKey, int fullmode, List<byte[]> pINdata) {
|
public byte[] SYD_SM3_LongData(byte[] pcData, byte[] procData, int iPkgNum) {
|
||||||
|
|
||||||
|
if ( pcData.length > MaxDataLenEachPack ) {
|
||||||
|
throw new IllegalArgumentException("单包数据超长");
|
||||||
|
}
|
||||||
|
|
||||||
|
ByteBuffer bb = ByteBuffer.allocate(10 * 1024);
|
||||||
|
PacketSN sn = PacketSN.gen();
|
||||||
|
bb.put( new byte[2] );
|
||||||
|
bb.put( sn.getSn().array() );
|
||||||
|
bb.put( "76".getBytes() );
|
||||||
|
bb.put( (byte) (0x30 + iPkgNum) ); // 包序号
|
||||||
|
|
||||||
|
// 填充消息数据长度
|
||||||
|
bb.put( String.format("%04d", pcData.length).getBytes() );
|
||||||
|
|
||||||
|
// 填充消息数据
|
||||||
|
bb.put( pcData );
|
||||||
|
|
||||||
|
if ( 0 == iPkgNum || 1 == iPkgNum ) {
|
||||||
|
// 无用户 id
|
||||||
|
bb.put( String.format("%02d", 0).getBytes() );
|
||||||
|
|
||||||
|
// 无公钥
|
||||||
|
bb.put( String.format("%04d", 0).getBytes() );
|
||||||
|
|
||||||
|
} else {
|
||||||
|
// 过渡数据
|
||||||
|
bb.put( String.format("%04d", procData.length).getBytes() );
|
||||||
|
bb.put( procData );
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// 重新计算长度
|
||||||
|
int len = bb.position();
|
||||||
|
len -= 2;
|
||||||
|
byte[] lenArray = new byte[ 2 ];
|
||||||
|
lenArray[0] = (byte)((len >> 8) & 0xFF);
|
||||||
|
lenArray[1] = (byte)( len & 0xFF);
|
||||||
|
|
||||||
|
bb.put( 0, (byte)((len >> 8) & 0xFF) );
|
||||||
|
bb.put( 1, (byte)( len & 0xFF) );
|
||||||
|
|
||||||
|
// 通信
|
||||||
|
synchronized (this) {
|
||||||
|
// 响应解析
|
||||||
|
bb = syncRead(syncSend(bb));
|
||||||
|
}
|
||||||
|
|
||||||
|
bb.flip();
|
||||||
|
bb.position( 12 );
|
||||||
|
byte[] code = new byte[2];
|
||||||
|
bb.get( code );
|
||||||
|
|
||||||
|
int retCode = Integer.valueOf( new String( code ) );
|
||||||
|
if ( 0 != retCode ) {
|
||||||
|
throw new SydApiException( retCode );
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( 0 == iPkgNum || 3 == iPkgNum ){
|
||||||
|
byte[] hash = new byte[ 32 ];
|
||||||
|
bb.get(hash);
|
||||||
|
return hash;
|
||||||
|
} else {
|
||||||
|
// 获取长度
|
||||||
|
byte[] iLenArray = new byte[4];
|
||||||
|
bb.get( iLenArray );
|
||||||
|
int ilen = Integer.valueOf( new String( iLenArray ), 10 );
|
||||||
|
byte[] data = new byte[ ilen ];
|
||||||
|
bb.get(data);
|
||||||
|
return data;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 短数据MAC计算接口,对数据进行SM4 MAC计算
|
||||||
|
*
|
||||||
|
* @param keyIndex:输入。计算mac所需要的密钥索引值
|
||||||
|
* @param pcData: 输入。计算mac所需要的数据。
|
||||||
|
*
|
||||||
|
* @return mac值(固定长度16字节)转HEX 字符串格式
|
||||||
|
* */
|
||||||
|
public String SYD_SM4Mac_ShortData(
|
||||||
|
String keyIndex,
|
||||||
|
byte[] pcData
|
||||||
|
){
|
||||||
|
ByteBuffer bb = ByteBuffer.allocate(10 * 1024);
|
||||||
|
PacketSN sn = PacketSN.gen();
|
||||||
|
bb.put( new byte[2] );
|
||||||
|
bb.put( sn.getSn().array() );
|
||||||
|
bb.put( "E0".getBytes() );
|
||||||
|
bb.put( (byte) 0x30 ); // 仅一块
|
||||||
|
bb.put( (byte) ( 0x38) ); // SM4 加密
|
||||||
|
bb.put( (byte) ( 0x32) ); // CBC
|
||||||
|
bb.put( (byte) ( 0x30) ); // ZEK
|
||||||
|
|
||||||
|
// 填充密钥
|
||||||
|
// 1A+K+27位的索引号
|
||||||
|
bb.put( keyIndex.getBytes() );
|
||||||
|
|
||||||
|
bb.put( (byte) ( 0x30) ); // 输入消息类型二进制
|
||||||
|
bb.put( (byte) ( 0x30) ); // 输出消息类型二进制
|
||||||
|
|
||||||
|
bb.put( (byte) ( 0x31) ); // 填充模式
|
||||||
|
bb.put( "0000".getBytes() ); // 填充字符
|
||||||
|
bb.put( (byte) ( 0x32) ); // 填充类型
|
||||||
|
|
||||||
|
// iv
|
||||||
|
byte[] iv = new byte[ 32 ];
|
||||||
|
Arrays.fill( iv, (byte)0x30 );
|
||||||
|
bb.put( iv );
|
||||||
|
|
||||||
|
// P 长度暂未支持
|
||||||
|
|
||||||
|
|
||||||
|
// 填充消息数据长度
|
||||||
|
bb.put( String.format("%03X", pcData.length).getBytes() );
|
||||||
|
|
||||||
|
// 填充消息数据
|
||||||
|
bb.put( pcData );
|
||||||
|
|
||||||
|
// 重新计算长度
|
||||||
|
int len = bb.position();
|
||||||
|
len -= 2;
|
||||||
|
byte[] lenArray = new byte[ 2 ];
|
||||||
|
lenArray[0] = (byte)((len >> 8) & 0xFF);
|
||||||
|
lenArray[1] = (byte)( len & 0xFF);
|
||||||
|
|
||||||
|
bb.put( 0, (byte)((len >> 8) & 0xFF) );
|
||||||
|
bb.put( 1, (byte)( len & 0xFF) );
|
||||||
|
|
||||||
|
// 通信
|
||||||
|
synchronized (this) {
|
||||||
|
// 响应解析
|
||||||
|
bb = syncRead(syncSend(bb));
|
||||||
|
}
|
||||||
|
|
||||||
|
bb.flip();
|
||||||
|
bb.position( 12 );
|
||||||
|
byte[] code = new byte[2];
|
||||||
|
bb.get( code );
|
||||||
|
|
||||||
|
int retCode = Integer.valueOf( new String( code ) );
|
||||||
|
if ( 0 != retCode ) {
|
||||||
|
throw new SydApiException( retCode );
|
||||||
|
}
|
||||||
|
|
||||||
|
// 跳过输出模式
|
||||||
|
bb.get();
|
||||||
|
|
||||||
|
// 获取长度
|
||||||
|
byte[] iLenArray = new byte[3];
|
||||||
|
bb.get( iLenArray );
|
||||||
|
int ilen = Integer.valueOf( new String( iLenArray ), 16 );
|
||||||
|
byte[] skip = new byte[ ilen - 16 ];
|
||||||
|
bb.get(skip);
|
||||||
|
byte[] mac = new byte[16];
|
||||||
|
bb.get(mac);
|
||||||
|
|
||||||
|
return Util.bytes2HexString(mac);
|
||||||
|
}
|
||||||
|
|
||||||
|
public byte[] SYD_SM4_LongData(int nAlg, int round, byte[] iv, String keyIndex, int fullmode, byte[] pcData, int iPkgNum) {
|
||||||
|
|
||||||
|
if ( pcData.length > MaxDataLenEachPack ) {
|
||||||
|
throw new IllegalArgumentException("单包数据超长");
|
||||||
|
}
|
||||||
|
|
||||||
|
ByteBuffer bb = ByteBuffer.allocate(10 * 1024);
|
||||||
|
PacketSN sn = PacketSN.gen();
|
||||||
|
bb.put( new byte[2] );
|
||||||
|
bb.put( sn.getSn().array() );
|
||||||
|
bb.put( "E0".getBytes() );
|
||||||
|
bb.put( (byte) (0x30 + iPkgNum) ); // 包序号
|
||||||
|
bb.put( (byte) ( 0x30 + nAlg) ); // 密钥模式
|
||||||
|
bb.put( (byte) ( 0x30 + round )); // 1=ECB 2=CBC
|
||||||
|
bb.put( (byte) ( 0x30) ); // ZEK
|
||||||
|
|
||||||
|
// 填充密钥
|
||||||
|
bb.put( keyIndex.getBytes() );
|
||||||
|
|
||||||
|
bb.put( (byte) ( 0x30) ); // 输入消息类型二进制
|
||||||
|
bb.put( (byte) ( 0x30) ); // 输出消息类型二进制
|
||||||
|
|
||||||
|
|
||||||
|
if( 0 == iPkgNum || 3 == iPkgNum || 4 == iPkgNum ) {
|
||||||
|
bb.put( (byte) ( 0x30 + fullmode) ); // 填充模式
|
||||||
|
bb.put( "0000".getBytes() ); // 填充字符
|
||||||
|
bb.put( (byte) ( 0x32) ); // 填充类型
|
||||||
|
}
|
||||||
|
|
||||||
|
// iv
|
||||||
|
if ( 2 == round ) {
|
||||||
|
if ( null == iv ) {
|
||||||
|
iv = new byte[ 32 ];
|
||||||
|
Arrays.fill( iv, (byte)0x30 );
|
||||||
|
}
|
||||||
|
bb.put( iv );
|
||||||
|
}
|
||||||
|
|
||||||
|
// P 长度暂未支持
|
||||||
|
|
||||||
|
|
||||||
|
// 填充消息数据长度
|
||||||
|
bb.put( String.format("%03X", pcData.length).getBytes() );
|
||||||
|
|
||||||
|
// 填充多个消息数据
|
||||||
|
bb.put( pcData );
|
||||||
|
|
||||||
|
// 重新计算长度
|
||||||
|
int len = bb.position();
|
||||||
|
len -= 2;
|
||||||
|
byte[] lenArray = new byte[ 2 ];
|
||||||
|
lenArray[0] = (byte)((len >> 8) & 0xFF);
|
||||||
|
lenArray[1] = (byte)( len & 0xFF);
|
||||||
|
|
||||||
|
bb.put( 0, (byte)((len >> 8) & 0xFF) );
|
||||||
|
bb.put( 1, (byte)( len & 0xFF) );
|
||||||
|
|
||||||
|
// 通信
|
||||||
|
synchronized (this) {
|
||||||
|
// 响应解析
|
||||||
|
bb = syncRead(syncSend(bb));
|
||||||
|
}
|
||||||
|
|
||||||
|
bb.flip();
|
||||||
|
bb.position( 12 );
|
||||||
|
byte[] code = new byte[2];
|
||||||
|
bb.get( code );
|
||||||
|
|
||||||
|
int retCode = Integer.valueOf( new String( code ) );
|
||||||
|
if ( 0 != retCode ) {
|
||||||
|
throw new SydApiException( retCode );
|
||||||
|
}
|
||||||
|
|
||||||
|
// 跳过输出模式
|
||||||
|
bb.get();
|
||||||
|
|
||||||
|
// 获取长度
|
||||||
|
byte[] iLenArray = new byte[3];
|
||||||
|
bb.get( iLenArray );
|
||||||
|
int ilen = Integer.valueOf( new String( iLenArray ), 16 );
|
||||||
|
|
||||||
|
// 获取长度的数据
|
||||||
|
byte[] d = new byte[ ilen ];
|
||||||
|
bb.get(d);
|
||||||
|
return d;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<byte[]> SYMEncryptDecryptBatchData(int nAlg, int round, byte[] iv, String[] seesionKey, int fullmode, List<byte[]> pINdata) {
|
||||||
|
|
||||||
int batchSize = pINdata.size();
|
int batchSize = pINdata.size();
|
||||||
if ( batchSize < 1 || batchSize > 10 ) {
|
if ( batchSize < 1 || batchSize > 10 ) {
|
||||||
@ -1989,14 +2297,14 @@ public class SydApi4j implements SydApi {
|
|||||||
// 解密
|
// 解密
|
||||||
for ( byte[]d : pINdata ) {
|
for ( byte[]d : pINdata ) {
|
||||||
if ( d.length > 1040 ) {
|
if ( d.length > 1040 ) {
|
||||||
throw new IllegalArgumentException("批量单数数据超长 1040");
|
throw new IllegalArgumentException("批量单数据超长 1040");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// 加密
|
// 加密
|
||||||
for ( byte[]d : pINdata ) {
|
for ( byte[]d : pINdata ) {
|
||||||
if ( d.length > 1024 ) {
|
if ( d.length > 1040 ) {
|
||||||
throw new IllegalArgumentException("批量单数数据超长 1024");
|
throw new IllegalArgumentException("批量单数据超长 1040");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -2009,7 +2317,7 @@ public class SydApi4j implements SydApi {
|
|||||||
bb.put( (byte) 0x34 ); // 批量加解密
|
bb.put( (byte) 0x34 ); // 批量加解密
|
||||||
bb.put( (byte) batchSize ); // 批量数
|
bb.put( (byte) batchSize ); // 批量数
|
||||||
bb.put( (byte) ( 0x30 + nAlg) ); // 密钥模式
|
bb.put( (byte) ( 0x30 + nAlg) ); // 密钥模式
|
||||||
bb.put( (byte) ( 0x31) ); // ECB
|
bb.put( (byte) ( 0x30 + round) ); // 1=ECB 2=CBC
|
||||||
bb.put( (byte) ( 0x30) ); // ZEK
|
bb.put( (byte) ( 0x30) ); // ZEK
|
||||||
|
|
||||||
// 填充多个密钥
|
// 填充多个密钥
|
||||||
@ -2024,10 +2332,20 @@ public class SydApi4j implements SydApi {
|
|||||||
bb.put( "0000".getBytes() ); // 填充字符
|
bb.put( "0000".getBytes() ); // 填充字符
|
||||||
bb.put( (byte) ( 0x32) ); // 填充类型
|
bb.put( (byte) ( 0x32) ); // 填充类型
|
||||||
|
|
||||||
// iv 暂未支持
|
// 多个 iv
|
||||||
// P 长度暂未支持
|
if ( 2 == round ) {
|
||||||
|
if ( null == iv ) {
|
||||||
|
iv = new byte[ 32 ];
|
||||||
|
Arrays.fill( iv, (byte)0x30 );
|
||||||
|
}
|
||||||
|
for (int i = 0 ; i < batchSize ; i ++ ) {
|
||||||
|
bb.put( iv );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// P 长度暂未支持
|
||||||
|
|
||||||
// 填充多个消息数据长度
|
// 填充多个消息数据长度
|
||||||
for ( byte[] data : pINdata ) {
|
for ( byte[] data : pINdata ) {
|
||||||
bb.put( String.format("%03X", data.length).getBytes() );
|
bb.put( String.format("%03X", data.length).getBytes() );
|
||||||
@ -3160,6 +3478,7 @@ public class SydApi4j implements SydApi {
|
|||||||
|
|
||||||
//1.1生成一个对称密钥(*) -> pass (对比之前添加了可产生ZMK加密下的密钥)
|
//1.1生成一个对称密钥(*) -> pass (对比之前添加了可产生ZMK加密下的密钥)
|
||||||
// 测试通过
|
// 测试通过
|
||||||
|
@Override
|
||||||
public RetWrap genSymKey(int mode, String keyType, char solution, String zmk) {
|
public RetWrap genSymKey(int mode, String keyType, char solution, String zmk) {
|
||||||
ProtoA0 proto = new ProtoA0();
|
ProtoA0 proto = new ProtoA0();
|
||||||
HashMap<String, Object> packet = new HashMap();
|
HashMap<String, Object> packet = new HashMap();
|
||||||
@ -4669,6 +4988,11 @@ public class SydApi4j implements SydApi {
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public byte[] SM3Hash(String publicKey, String userId, byte[] msg){
|
||||||
|
return SM3Hash(publicKey, null, null, userId, msg);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public byte[] SM3Hash(String publicKey, byte[] msg, int block, byte[] mac) {
|
public byte[] SM3Hash(String publicKey, byte[] msg, int block, byte[] mac) {
|
||||||
|
|
||||||
@ -8451,6 +8775,7 @@ public class SydApi4j implements SydApi {
|
|||||||
* @return 目的 ZPK 下加密的目的 PIN 块
|
* @return 目的 ZPK 下加密的目的 PIN 块
|
||||||
*/
|
*/
|
||||||
// 测试通过
|
// 测试通过
|
||||||
|
@Override
|
||||||
public String transPINFromTPKToZPK(String tpk, String zpk, int sca, int dca, int spt, int dpt, String pin, String account) {
|
public String transPINFromTPKToZPK(String tpk, String zpk, int sca, int dca, int spt, int dpt, String pin, String account) {
|
||||||
ProtoCA proto = new ProtoCA();
|
ProtoCA proto = new ProtoCA();
|
||||||
|
|
||||||
|
|||||||
@ -22,7 +22,7 @@ public class TestBatchData {
|
|||||||
List<byte[]> pINdata = new ArrayList<byte[]>();
|
List<byte[]> pINdata = new ArrayList<byte[]>();
|
||||||
pINdata.add("12345678".getBytes());
|
pINdata.add("12345678".getBytes());
|
||||||
|
|
||||||
List<byte[]> datas = api.SYMEncryptDecryptBatchData(0x8, keys, 1, pINdata);
|
// List<byte[]> datas = api.SYMEncryptDecryptBatchData(0x8, keys, 1, pINdata);
|
||||||
|
|
||||||
// boolean pass = api.SM2Verify( 1, Util.hexString2Bytes(pk), Util.hexString2Bytes(inHexData), sign );
|
// boolean pass = api.SM2Verify( 1, Util.hexString2Bytes(pk), Util.hexString2Bytes(inHexData), sign );
|
||||||
}
|
}
|
||||||
|
|||||||
31
src/test/java/com/sunyard/sydapi/test/TestSM3PK.java
Normal file
31
src/test/java/com/sunyard/sydapi/test/TestSM3PK.java
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
package com.sunyard.sydapi.test;
|
||||||
|
|
||||||
|
|
||||||
|
import com.sunyard.proto.Util;
|
||||||
|
import racal.sunyard.main.SydApi4j;
|
||||||
|
|
||||||
|
|
||||||
|
import java.io.UnsupportedEncodingException;
|
||||||
|
|
||||||
|
public class TestSM3PK {
|
||||||
|
public static void main(String[] args) throws UnsupportedEncodingException {
|
||||||
|
System.setProperty("com.sunyard.sydapi4j.debug", "true");
|
||||||
|
|
||||||
|
SydApi4j.SYD_Set_Parameter_HA("unkown", "192.168.0.200", 8889, 1000);
|
||||||
|
|
||||||
|
SydApi4j api = (SydApi4j) new SydApi4j();//.connect("wuyong.fullstack.club" , 8889, null,1000);
|
||||||
|
String certId = "4008258105";
|
||||||
|
try {
|
||||||
|
// "03420004" +
|
||||||
|
String pk = "034200043c59ccb2c52e034337fad49eca0095587eb40e24ffc642d07e0c911ea4a3b0e94f11b92b51047f6f75badf5ab2fc2e15ba4dfddf95869d4fa8d8852dea811d4b";
|
||||||
|
|
||||||
|
byte[] ret = api.SM3Hash(pk, certId, Util.hexString2Bytes("636572745F69643D3430303832353831303526636F64653D3430303034266D73673DE7BCBAE5B091E5BF85E98089E58F82E695B0267369676E5F747970653D534D32267375625F636F64653D75702E6D697373696E672D6F72672D706964267375625F6D73673DE7BCBAE5B0916F72675F706964205B5550303231303031325D"));
|
||||||
|
|
||||||
|
System.out.println( Util.bytes2HexString( ret ) );
|
||||||
|
} finally {
|
||||||
|
api.disconnect();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue
Block a user