Merge branch 'dev-icbc' into dev-shangqing

# Conflicts:
#	.gitignore
#	doc/java接口说明文档.docx
#	src/main/java/racal/sunyard/main/SydApi4j.java
#	src/test/java/com/sunyard/sydapi/test/TestAllMethods.java
#	src/test/java/com/sunyard/sydapi/test/TestSV.java
This commit is contained in:
cheney
2022-08-18 14:58:18 +08:00
17 changed files with 646 additions and 674 deletions
@@ -0,0 +1,109 @@
package com.sunyard;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;
/**
* 管理多线程间对象
* 类似 ThreadLocal
* @param <T>
*/
public class MutiThreadHander<T> {
private static class Handler<T> {
private T obj = null;
private long creatAt = System.currentTimeMillis();
private long lastGetAt = System.currentTimeMillis();
public Handler(T obj) {
this.obj = obj;
}
public T getObj() {
return obj;
}
public long getCreatAt() {
return creatAt;
}
public long getLastGetAt() {
return lastGetAt;
}
}
private final Map<Thread, Handler> handers = new HashMap<Thread, Handler>();
private ScheduledExecutorService gcThread = Executors.newScheduledThreadPool(1);
private long maxLiveMillis = 8 * 3600 * 1000;
private long maxIdleMillis = 3600 * 1000;
private long checkEveryMillis = 5 * 60 * 1000;
public MutiThreadHander() {
gcThread.scheduleWithFixedDelay(new Runnable() {
@Override
public void run() {
try {
if ( handers.size() <= 0 ) {
return;
}
long now = System.currentTimeMillis();
Iterator<Map.Entry<Thread, Handler>>it = handers.entrySet().iterator();
while ( it.hasNext() ){
Map.Entry<Thread, Handler> entry = it.next();
// check maxLiveMillis
if ( entry.getValue().getCreatAt() - now > maxLiveMillis ){
synchronized ( handers ){
it.remove();
}
}
// check maxIdleMillis
if ( entry.getValue().getLastGetAt() - now > maxIdleMillis ){
synchronized ( handers ){
it.remove();
}
}
}
} catch ( Exception e) {
e.printStackTrace();
}
}
}, checkEveryMillis, checkEveryMillis, TimeUnit.MILLISECONDS );
}
protected T initialValue() {
return null;
}
public void clear(){
synchronized ( handers ) {
handers.remove( Thread.currentThread() );
}
}
public void set(T obj){
synchronized ( handers ) {
handers.put( Thread.currentThread() , new Handler(obj));
}
}
public T get(){
synchronized ( handers ) {
Handler hander = handers.get( Thread.currentThread() );
if ( null == hander ) {
T o = initialValue();
hander = new Handler( o );
handers.put( Thread.currentThread(), hander );
}
return (T) hander.getObj();
}
}
}
@@ -3,6 +3,7 @@ package com.sunyard.inf;
import com.sunyard.RetWrap;
import java.io.UnsupportedEncodingException;
import java.util.List;
/**
* 对称加解密相关接口
@@ -273,6 +274,9 @@ interface SydSYMApi {
*/
byte[] SYMEncryptData(int nAlg, String seesionKey, int fullmode, byte[] pINdata);
List<byte[]> SYMEncryptDecryptBatchData(int nAlg, String[] seesionKey, int fullmode, List<byte[]> pINdata);
/**
* 用输入的会话密钥,对指定报文数据进行加密处理。
*
+3 -3
View File
@@ -60,8 +60,8 @@ interface SydAttachedSVApi {
* @param orgData 要签名的信息
* @return 签名结果
*/
String SM2SignC(int flag, String privateKey, byte[] publicKey, byte[] orgData);
String SM2SignC(int flag, String pUserID, String privateKey, byte[] publicKey, byte[] orgData);
byte[] SM2SignC(int flag, String privateKey, byte[] publicKey, byte[] orgData);
byte[] SM2SignC(int flag, String pUserID, String privateKey, byte[] publicKey, byte[] orgData);
/**
* SM2 私钥签名
* @param pUserID 使用者的 ID,最大长度为 16 位数字,右对齐。
@@ -142,7 +142,7 @@ interface SydAttachedSVApi {
int nOrgDataType,
byte[] publicKey,
byte[] orgData,
String sign
byte[] sign
);
@@ -117,13 +117,13 @@ public interface SydHAApi {
* @param nOrgDataType 签名数据类型,SydApi.DATA_ORIGIN(1) 原始数据 SydApi.DATA_HASH(0) : hash 后的类型
* @param publicKey 公钥串,DER编码,HEX格式
* @param orgData 待签名的原始数据,“签名数据类型”为 0 时:HASH 值。“签名数据类型”为 1 时:要签名的信息
* @param base64Sign 签名数据 (DER 编码 + Base64 编码)
* @param sign S+R
* @return 验签是否通过
*/
public boolean SM2Verify(
int nOrgDataType,
byte[] publicKey,
byte[] orgData,
String base64Sign
byte[] sign
);
}