本地保存
This commit is contained in:
parent
b26aab01a4
commit
6f833730c2
@ -1,183 +0,0 @@
|
|||||||
package com.sunyard.util;
|
|
||||||
|
|
||||||
import java.nio.ByteBuffer;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @Author:Cheney
|
|
||||||
* @Date:2023/7/27 11:16
|
|
||||||
*/
|
|
||||||
public class FrameCache {
|
|
||||||
private static ByteBuffer sm2p1;
|
|
||||||
private static ByteBuffer sm2p1v;
|
|
||||||
private static ByteBuffer rsap1;
|
|
||||||
private static ByteBuffer rsap1v;
|
|
||||||
private static ByteBuffer sm2det;
|
|
||||||
private static ByteBuffer sm2detv;
|
|
||||||
private static ByteBuffer rsadet;
|
|
||||||
private static ByteBuffer rsadetv;
|
|
||||||
|
|
||||||
private static ByteBuffer sm2detres;
|
|
||||||
|
|
||||||
public static ByteBuffer getSm2detres() {
|
|
||||||
return sm2detres;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void setSm2detres(ByteBuffer sm2detres) {
|
|
||||||
FrameCache.sm2detres = sm2detres;
|
|
||||||
}
|
|
||||||
|
|
||||||
private static String P7sign;
|
|
||||||
|
|
||||||
public static String getP7sign() {
|
|
||||||
return P7sign;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void setP7sign(String p7sign) {
|
|
||||||
P7sign = p7sign;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static ByteBuffer getSm2p1() {
|
|
||||||
return sm2p1;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void setSm2p1(ByteBuffer sm2p1) {
|
|
||||||
FrameCache.sm2p1 = sm2p1;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static ByteBuffer getSm2p1v() {
|
|
||||||
return sm2p1v;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void setSm2p1v(ByteBuffer sm2p1v) {
|
|
||||||
FrameCache.sm2p1v = sm2p1v;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static ByteBuffer getRsap1() {
|
|
||||||
return rsap1;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void setRsap1(ByteBuffer rsap1) {
|
|
||||||
FrameCache.rsap1 = rsap1;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static ByteBuffer getRsap1v() {
|
|
||||||
return rsap1v;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void setRsap1v(ByteBuffer rsap1v) {
|
|
||||||
FrameCache.rsap1v = rsap1v;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static ByteBuffer getSm2det() {
|
|
||||||
return sm2det;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void setSm2det(ByteBuffer sm2det) {
|
|
||||||
FrameCache.sm2det = sm2det;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static ByteBuffer getSm2detv() {
|
|
||||||
return sm2detv;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void setSm2detv(ByteBuffer sm2detv) {
|
|
||||||
FrameCache.sm2detv = sm2detv;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static ByteBuffer getRsadet() {
|
|
||||||
return rsadet;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void setRsadet(ByteBuffer rsadet) {
|
|
||||||
FrameCache.rsadet = rsadet;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static ByteBuffer getRsadetv() {
|
|
||||||
return rsadetv;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void setRsadetv(ByteBuffer rsadetv) {
|
|
||||||
FrameCache.rsadetv = rsadetv;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static ByteBuffer getSm2att() {
|
|
||||||
return sm2att;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void setSm2att(ByteBuffer sm2att) {
|
|
||||||
FrameCache.sm2att = sm2att;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static ByteBuffer getSm2attv() {
|
|
||||||
return sm2attv;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void setSm2attv(ByteBuffer sm2attv) {
|
|
||||||
FrameCache.sm2attv = sm2attv;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static ByteBuffer getRsaatt() {
|
|
||||||
return rsaatt;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void setRsaatt(ByteBuffer rsaatt) {
|
|
||||||
FrameCache.rsaatt = rsaatt;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static ByteBuffer getRsaattv() {
|
|
||||||
return rsaattv;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void setRsaattv(ByteBuffer rsaattv) {
|
|
||||||
FrameCache.rsaattv = rsaattv;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static ByteBuffer getSm2gen() {
|
|
||||||
return sm2gen;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void setSm2gen(ByteBuffer sm2gen) {
|
|
||||||
FrameCache.sm2gen = sm2gen;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static ByteBuffer getSm2den() {
|
|
||||||
return sm2den;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void setSm2den(ByteBuffer sm2den) {
|
|
||||||
FrameCache.sm2den = sm2den;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static ByteBuffer getRsagen() {
|
|
||||||
return rsagen;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void setRsagen(ByteBuffer rsagen) {
|
|
||||||
FrameCache.rsagen = rsagen;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static ByteBuffer getRsaden() {
|
|
||||||
return rsaden;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void setRsaden(ByteBuffer rsaden) {
|
|
||||||
FrameCache.rsaden = rsaden;
|
|
||||||
}
|
|
||||||
|
|
||||||
private static ByteBuffer sm2att;
|
|
||||||
private static ByteBuffer sm2attv;
|
|
||||||
private static ByteBuffer rsaatt;
|
|
||||||
private static ByteBuffer rsaattv;
|
|
||||||
private static ByteBuffer sm2gen;
|
|
||||||
private static ByteBuffer sm2den;
|
|
||||||
private static ByteBuffer rsagen;
|
|
||||||
private static ByteBuffer rsaden;
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// private static ByteBuffer res;
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
@ -464,8 +464,6 @@ public class SydApi4j implements SydApi {
|
|||||||
data.put("hash", hash);
|
data.put("hash", hash);
|
||||||
ByteBuffer bb = proto.rend(packet);
|
ByteBuffer bb = proto.rend(packet);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
synchronized(this) {
|
synchronized(this) {
|
||||||
bb = this.syncRead(this.syncSend(bb));
|
bb = this.syncRead(this.syncSend(bb));
|
||||||
|
|
||||||
@ -523,9 +521,6 @@ public class SydApi4j implements SydApi {
|
|||||||
Proto8003 proto = new Proto8003();
|
Proto8003 proto = new Proto8003();
|
||||||
PacketSN sn = PacketSN.gen();
|
PacketSN sn = PacketSN.gen();
|
||||||
HashMap<String, Object> packet = new HashMap<String, Object>();
|
HashMap<String, Object> packet = new HashMap<String, Object>();
|
||||||
ByteBuffer bb = null;
|
|
||||||
if (null ==FrameCache.getRsap1()) {
|
|
||||||
|
|
||||||
|
|
||||||
byte[] dn = new byte[256];
|
byte[] dn = new byte[256];
|
||||||
byte[] s = null;
|
byte[] s = null;
|
||||||
@ -560,12 +555,7 @@ public class SydApi4j implements SydApi {
|
|||||||
data.put("signData", orgData);
|
data.put("signData", orgData);
|
||||||
data.put("hash", hash);
|
data.put("hash", hash);
|
||||||
// 渲染发送
|
// 渲染发送
|
||||||
bb = proto.rend(packet);
|
ByteBuffer bb = proto.rend(packet);
|
||||||
FrameCache.setRsap1(bb);
|
|
||||||
}else{
|
|
||||||
bb = FrameCache.getRsap1();
|
|
||||||
}
|
|
||||||
|
|
||||||
synchronized (this) {
|
synchronized (this) {
|
||||||
// 响应解析
|
// 响应解析
|
||||||
bb = syncRead(syncSend(bb));
|
bb = syncRead(syncSend(bb));
|
||||||
@ -600,7 +590,6 @@ public class SydApi4j implements SydApi {
|
|||||||
PacketSN sn = PacketSN.gen();
|
PacketSN sn = PacketSN.gen();
|
||||||
HashMap<String, Object> packet = new HashMap();
|
HashMap<String, Object> packet = new HashMap();
|
||||||
|
|
||||||
|
|
||||||
sign = ASN1Util.alignSignDer(sign);
|
sign = ASN1Util.alignSignDer(sign);
|
||||||
byte[] dn = new byte[256];
|
byte[] dn = new byte[256];
|
||||||
byte[] s = null;
|
byte[] s = null;
|
||||||
@ -680,9 +669,6 @@ public class SydApi4j implements SydApi {
|
|||||||
Proto8004 proto = new Proto8004();
|
Proto8004 proto = new Proto8004();
|
||||||
HashMap<String, Object> packet = new HashMap<String, Object>();
|
HashMap<String, Object> packet = new HashMap<String, Object>();
|
||||||
PacketSN sn = PacketSN.gen();
|
PacketSN sn = PacketSN.gen();
|
||||||
ByteBuffer bb =null;
|
|
||||||
if (null == FrameCache.getRsap1v()) {
|
|
||||||
|
|
||||||
|
|
||||||
byte[] dn = new byte[256];
|
byte[] dn = new byte[256];
|
||||||
byte[] s = null;
|
byte[] s = null;
|
||||||
@ -716,11 +702,7 @@ public class SydApi4j implements SydApi {
|
|||||||
data.put("hash", hashData);
|
data.put("hash", hashData);
|
||||||
data.put("returnSign$option", 0);
|
data.put("returnSign$option", 0);
|
||||||
// 渲染发送
|
// 渲染发送
|
||||||
bb = proto.rend(packet);
|
ByteBuffer bb = proto.rend(packet);
|
||||||
FrameCache.setRsap1v(bb);
|
|
||||||
}else{
|
|
||||||
bb = FrameCache.getRsap1v();
|
|
||||||
}
|
|
||||||
|
|
||||||
synchronized (this) {
|
synchronized (this) {
|
||||||
byte[] b = syncSend(bb);
|
byte[] b = syncSend(bb);
|
||||||
@ -896,8 +878,7 @@ public class SydApi4j implements SydApi {
|
|||||||
Proto8005 proto = new Proto8005();
|
Proto8005 proto = new Proto8005();
|
||||||
HashMap<String, Object> packet = new HashMap<String, Object>();
|
HashMap<String, Object> packet = new HashMap<String, Object>();
|
||||||
PacketSN sn = PacketSN.gen();
|
PacketSN sn = PacketSN.gen();
|
||||||
ByteBuffer bb = null;
|
|
||||||
if (null == FrameCache.getSm2det()) {
|
|
||||||
byte[] dn = new byte[256];
|
byte[] dn = new byte[256];
|
||||||
byte[] s = null;
|
byte[] s = null;
|
||||||
try {
|
try {
|
||||||
@ -924,23 +905,15 @@ public class SydApi4j implements SydApi {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 渲染发送
|
// 渲染发送
|
||||||
bb = proto.rend(packet);
|
ByteBuffer bb = proto.rend(packet);
|
||||||
FrameCache.setSm2det(bb);
|
|
||||||
}else{
|
|
||||||
bb = FrameCache.getSm2det();
|
|
||||||
}
|
|
||||||
|
|
||||||
synchronized (this) {
|
synchronized (this) {
|
||||||
// 响应解析
|
// 响应解析
|
||||||
bb = syncRead(syncSend(bb));
|
bb = syncRead(syncSend(bb));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
|
||||||
if (null == FrameCache.getP7sign()) {
|
|
||||||
Packet p = proto.parse(bb);
|
Packet p = proto.parse(bb);
|
||||||
Map<String, Object> ret = p.toMap();
|
Map<String, Object> ret = p.toMap();
|
||||||
|
|
||||||
if (
|
if (
|
||||||
!Arrays.equals(sn.getSn().array(), ((PacketSection) ret.get("header")).getBytes())
|
!Arrays.equals(sn.getSn().array(), ((PacketSection) ret.get("header")).getBytes())
|
||||||
) {
|
) {
|
||||||
@ -956,11 +929,7 @@ public class SydApi4j implements SydApi {
|
|||||||
}
|
}
|
||||||
|
|
||||||
String signature = ((PacketSection) ret.get("signature")).getString();
|
String signature = ((PacketSection) ret.get("signature")).getString();
|
||||||
FrameCache.setP7sign(signature);
|
|
||||||
return signature;
|
return signature;
|
||||||
}else{
|
|
||||||
return FrameCache.getP7sign();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -972,8 +941,6 @@ public class SydApi4j implements SydApi {
|
|||||||
HashMap<String, Object> packet = new HashMap<String, Object>();
|
HashMap<String, Object> packet = new HashMap<String, Object>();
|
||||||
PacketSN sn = PacketSN.gen();
|
PacketSN sn = PacketSN.gen();
|
||||||
|
|
||||||
ByteBuffer bb =null;
|
|
||||||
if (null == FrameCache.getSm2detv()) {
|
|
||||||
HashMap<String, Object> data = new HashMap<String, Object>();
|
HashMap<String, Object> data = new HashMap<String, Object>();
|
||||||
packet.put("data", data);
|
packet.put("data", data);
|
||||||
|
|
||||||
@ -990,11 +957,7 @@ public class SydApi4j implements SydApi {
|
|||||||
data.put("signData", sign.getBytes());
|
data.put("signData", sign.getBytes());
|
||||||
data.put("flag$option", 0);
|
data.put("flag$option", 0);
|
||||||
// 渲染发送
|
// 渲染发送
|
||||||
bb = proto.rend(packet);
|
ByteBuffer bb = proto.rend(packet);
|
||||||
FrameCache.setSm2detv(bb);
|
|
||||||
}else{
|
|
||||||
bb = FrameCache.getSm2detv();
|
|
||||||
}
|
|
||||||
|
|
||||||
synchronized (this) {
|
synchronized (this) {
|
||||||
// 响应解析
|
// 响应解析
|
||||||
@ -1100,9 +1063,6 @@ public class SydApi4j implements SydApi {
|
|||||||
// 填充数据
|
// 填充数据
|
||||||
HashMap<String, Object> packet = new HashMap<String, Object>();
|
HashMap<String, Object> packet = new HashMap<String, Object>();
|
||||||
PacketSN sn = PacketSN.gen();
|
PacketSN sn = PacketSN.gen();
|
||||||
|
|
||||||
ByteBuffer bb= null;
|
|
||||||
if(null == FrameCache.getRsadetv()) {
|
|
||||||
HashMap<String, Object> data = new HashMap<String, Object>();
|
HashMap<String, Object> data = new HashMap<String, Object>();
|
||||||
packet.put("data", data);
|
packet.put("data", data);
|
||||||
|
|
||||||
@ -1135,11 +1095,7 @@ public class SydApi4j implements SydApi {
|
|||||||
data.put("signData", sign.getBytes());
|
data.put("signData", sign.getBytes());
|
||||||
data.put("flag$option", 0);
|
data.put("flag$option", 0);
|
||||||
// 渲染发送
|
// 渲染发送
|
||||||
bb = proto.rend(packet);
|
ByteBuffer bb = proto.rend(packet);
|
||||||
FrameCache.setRsadetv(bb);
|
|
||||||
}else{
|
|
||||||
bb = FrameCache.getRsadet();
|
|
||||||
}
|
|
||||||
|
|
||||||
synchronized (this) {
|
synchronized (this) {
|
||||||
// 响应解析
|
// 响应解析
|
||||||
@ -1353,8 +1309,6 @@ public class SydApi4j implements SydApi {
|
|||||||
Proto8005 proto = new Proto8005();
|
Proto8005 proto = new Proto8005();
|
||||||
HashMap<String, Object> packet = new HashMap<String, Object>();
|
HashMap<String, Object> packet = new HashMap<String, Object>();
|
||||||
PacketSN sn = PacketSN.gen();
|
PacketSN sn = PacketSN.gen();
|
||||||
ByteBuffer bb = null;
|
|
||||||
if ( null == FrameCache.getRsadet()) {
|
|
||||||
|
|
||||||
byte[] dn = new byte[256];
|
byte[] dn = new byte[256];
|
||||||
byte[] s = null;
|
byte[] s = null;
|
||||||
@ -1399,11 +1353,7 @@ public class SydApi4j implements SydApi {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 渲染发送
|
// 渲染发送
|
||||||
bb = proto.rend(packet);
|
ByteBuffer bb = proto.rend(packet);
|
||||||
FrameCache.setRsadet(bb);
|
|
||||||
}else{
|
|
||||||
bb = FrameCache.getRsadet();
|
|
||||||
}
|
|
||||||
|
|
||||||
synchronized (this) {
|
synchronized (this) {
|
||||||
// 响应解析
|
// 响应解析
|
||||||
@ -3184,8 +3134,7 @@ public class SydApi4j implements SydApi {
|
|||||||
// 填充数据
|
// 填充数据
|
||||||
PacketSN sn = PacketSN.gen();
|
PacketSN sn = PacketSN.gen();
|
||||||
HashMap<String, Object> packet = new HashMap<String, Object>();
|
HashMap<String, Object> packet = new HashMap<String, Object>();
|
||||||
ByteBuffer bb =null;
|
|
||||||
if (null == FrameCache.getRsagen()) {
|
|
||||||
packet.put("header", sn.getSn().array());
|
packet.put("header", sn.getSn().array());
|
||||||
HashMap<String, Object> data = new HashMap<String, Object>();
|
HashMap<String, Object> data = new HashMap<String, Object>();
|
||||||
data.put("alg$option", alg);
|
data.put("alg$option", alg);
|
||||||
@ -3209,11 +3158,8 @@ public class SydApi4j implements SydApi {
|
|||||||
|
|
||||||
packet.put("data", data);
|
packet.put("data", data);
|
||||||
// 渲染发送 耗时长
|
// 渲染发送 耗时长
|
||||||
bb = proto.rend(packet);
|
ByteBuffer bb = proto.rend(packet);
|
||||||
FrameCache.setRsagen(bb);
|
|
||||||
}else{
|
|
||||||
bb = FrameCache.getRsagen();
|
|
||||||
}
|
|
||||||
synchronized (this) {
|
synchronized (this) {
|
||||||
// 响应解析
|
// 响应解析
|
||||||
bb = syncRead(syncSend(bb));
|
bb = syncRead(syncSend(bb));
|
||||||
@ -3843,8 +3789,6 @@ public class SydApi4j implements SydApi {
|
|||||||
PacketSN sn = PacketSN.gen();
|
PacketSN sn = PacketSN.gen();
|
||||||
HashMap<String, Object> packet = new HashMap<String, Object>();
|
HashMap<String, Object> packet = new HashMap<String, Object>();
|
||||||
|
|
||||||
ByteBuffer bb =null ;
|
|
||||||
if(null == FrameCache.getSm2den()) {
|
|
||||||
packet.put("header", sn.getSn().array());
|
packet.put("header", sn.getSn().array());
|
||||||
HashMap<String, Object> data = new HashMap<String, Object>();
|
HashMap<String, Object> data = new HashMap<String, Object>();
|
||||||
if (pFlag) {
|
if (pFlag) {
|
||||||
@ -3862,12 +3806,8 @@ public class SydApi4j implements SydApi {
|
|||||||
packet.put("data", data);
|
packet.put("data", data);
|
||||||
|
|
||||||
// 渲染发送
|
// 渲染发送
|
||||||
bb = proto.rend(packet);
|
ByteBuffer bb = proto.rend(packet);
|
||||||
FrameCache.setSm2den(bb);
|
|
||||||
}
|
|
||||||
else{
|
|
||||||
bb = FrameCache.getSm2den();
|
|
||||||
}
|
|
||||||
synchronized (this) {
|
synchronized (this) {
|
||||||
// 响应解析
|
// 响应解析
|
||||||
bb = syncRead(syncSend(bb));
|
bb = syncRead(syncSend(bb));
|
||||||
@ -3918,8 +3858,6 @@ public class SydApi4j implements SydApi {
|
|||||||
PacketSN sn = PacketSN.gen();
|
PacketSN sn = PacketSN.gen();
|
||||||
HashMap<String, Object> packet = new HashMap<String, Object>();
|
HashMap<String, Object> packet = new HashMap<String, Object>();
|
||||||
|
|
||||||
ByteBuffer bb =null;
|
|
||||||
if (null == FrameCache.getRsaden()) {
|
|
||||||
packet.put("header", sn.getSn().array());
|
packet.put("header", sn.getSn().array());
|
||||||
HashMap<String, Object> data = new HashMap<String, Object>();
|
HashMap<String, Object> data = new HashMap<String, Object>();
|
||||||
data.put("pFlag", "R");
|
data.put("pFlag", "R");
|
||||||
@ -3938,11 +3876,8 @@ public class SydApi4j implements SydApi {
|
|||||||
packet.put("data", data);
|
packet.put("data", data);
|
||||||
|
|
||||||
// 渲染发送
|
// 渲染发送
|
||||||
bb = proto.rend(packet);
|
ByteBuffer bb = proto.rend(packet);
|
||||||
FrameCache.setRsaden(bb);
|
|
||||||
}else{
|
|
||||||
bb = FrameCache.getRsaden();
|
|
||||||
}
|
|
||||||
synchronized (this) {
|
synchronized (this) {
|
||||||
// 响应解析
|
// 响应解析
|
||||||
bb = syncRead(syncSend(bb));
|
bb = syncRead(syncSend(bb));
|
||||||
@ -12104,9 +12039,6 @@ public class SydApi4j implements SydApi {
|
|||||||
Proto8018 proto = new Proto8018();
|
Proto8018 proto = new Proto8018();
|
||||||
HashMap<String, Object> packet = new HashMap<String, Object>();
|
HashMap<String, Object> packet = new HashMap<String, Object>();
|
||||||
PacketSN sn = PacketSN.gen();
|
PacketSN sn = PacketSN.gen();
|
||||||
ByteBuffer bb =null;
|
|
||||||
if(null == FrameCache.getRsaatt()) {
|
|
||||||
|
|
||||||
|
|
||||||
byte[] dn = new byte[256];
|
byte[] dn = new byte[256];
|
||||||
byte[] s = null;
|
byte[] s = null;
|
||||||
@ -12137,11 +12069,7 @@ public class SydApi4j implements SydApi {
|
|||||||
data.put("infoData", orgData);
|
data.put("infoData", orgData);
|
||||||
|
|
||||||
// 渲染发送
|
// 渲染发送
|
||||||
bb = proto.rend(packet);
|
ByteBuffer bb = proto.rend(packet);
|
||||||
FrameCache.setRsaatt(bb);
|
|
||||||
}else{
|
|
||||||
bb = FrameCache.getRsaatt();
|
|
||||||
}
|
|
||||||
|
|
||||||
synchronized (this) {
|
synchronized (this) {
|
||||||
// 响应解析
|
// 响应解析
|
||||||
@ -12176,9 +12104,7 @@ public class SydApi4j implements SydApi {
|
|||||||
Proto8018 proto = new Proto8018();
|
Proto8018 proto = new Proto8018();
|
||||||
HashMap<String, Object> packet = new HashMap<String, Object>();
|
HashMap<String, Object> packet = new HashMap<String, Object>();
|
||||||
PacketSN sn = PacketSN.gen();
|
PacketSN sn = PacketSN.gen();
|
||||||
ByteBuffer bb =null;
|
|
||||||
|
|
||||||
if (null == FrameCache.getSm2att()) {
|
|
||||||
byte[] dn = new byte[256];
|
byte[] dn = new byte[256];
|
||||||
byte[] s = null;
|
byte[] s = null;
|
||||||
try {
|
try {
|
||||||
@ -12198,12 +12124,7 @@ public class SydApi4j implements SydApi {
|
|||||||
data.put("infoData", orgData);
|
data.put("infoData", orgData);
|
||||||
|
|
||||||
// 渲染发送
|
// 渲染发送
|
||||||
bb = proto.rend(packet);
|
ByteBuffer bb = proto.rend(packet);
|
||||||
FrameCache.setSm2att(bb);
|
|
||||||
|
|
||||||
}else{
|
|
||||||
bb = FrameCache.getSm2att();
|
|
||||||
}
|
|
||||||
|
|
||||||
synchronized (this) {
|
synchronized (this) {
|
||||||
// 响应解析
|
// 响应解析
|
||||||
@ -12250,8 +12171,7 @@ public class SydApi4j implements SydApi {
|
|||||||
HashMap<String, Object> packet = new HashMap<String, Object>();
|
HashMap<String, Object> packet = new HashMap<String, Object>();
|
||||||
HashMap<String, Object> data = new HashMap<String, Object>();
|
HashMap<String, Object> data = new HashMap<String, Object>();
|
||||||
PacketSN sn = PacketSN.gen();
|
PacketSN sn = PacketSN.gen();
|
||||||
ByteBuffer bb = null;
|
|
||||||
if(null == FrameCache.getSm2attv()) {
|
|
||||||
packet.put("data", data);
|
packet.put("data", data);
|
||||||
|
|
||||||
packet.put("header", sn.getSn().array());
|
packet.put("header", sn.getSn().array());
|
||||||
@ -12260,11 +12180,7 @@ public class SydApi4j implements SydApi {
|
|||||||
data.put("flag$option", 0);
|
data.put("flag$option", 0);
|
||||||
|
|
||||||
// 渲染发送
|
// 渲染发送
|
||||||
bb = proto.rend(packet);
|
ByteBuffer bb = proto.rend(packet);
|
||||||
FrameCache.setSm2attv(bb);
|
|
||||||
}else{
|
|
||||||
bb = FrameCache.getSm2attv();
|
|
||||||
}
|
|
||||||
|
|
||||||
synchronized (this) {
|
synchronized (this) {
|
||||||
// 响应解析
|
// 响应解析
|
||||||
|
|||||||
39
src/test/java/sample/Sample4GH.java
Normal file
39
src/test/java/sample/Sample4GH.java
Normal file
@ -0,0 +1,39 @@
|
|||||||
|
package sample;
|
||||||
|
|
||||||
|
import com.sunyard.proto.Util;
|
||||||
|
import racal.sunyard.main.SydApi4j;
|
||||||
|
import racal.sunyard.main.SydApiBuilder;
|
||||||
|
|
||||||
|
public class Sample4GH {
|
||||||
|
private static final String SM2dn = "C=CN,O=CFCA OCA1,OU=YCCA,OU=Individual-2,CN=YCCA@黄金交易所@Zhuangj@1";
|
||||||
|
private static final String SM2dn2 = "C=CN,O=SM2,OU=test,CN=1";
|
||||||
|
private static final String RSAdn = "C=cn,O=CFCA TEST CA,OU=NCS2,OU=Enterprises,CN=041@Z402451000010@ShanDong@00000001";
|
||||||
|
private static final byte[] orgData = new byte[ 1024];
|
||||||
|
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
|
||||||
|
//设置连接
|
||||||
|
SydApiBuilder builder = new SydApiBuilder().setIp("172.16.17.161");
|
||||||
|
SydApi4j api = (SydApi4j) builder.build();
|
||||||
|
|
||||||
|
byte[] nakedSign = api.SYD_NakedSign(SM2dn, orgData, (byte[]) null);
|
||||||
|
System.out.println("裸签"+nakedSign);
|
||||||
|
|
||||||
|
boolean nakedVerify = api.SYD_NakedVerify(SM2dn, nakedSign, orgData, (byte[]) null);
|
||||||
|
System.out.println("裸签验签"+nakedVerify);
|
||||||
|
|
||||||
|
String detachedSign = api.detachedSign(1, orgData, SM2dn);
|
||||||
|
System.out.println("det签名"+detachedSign);
|
||||||
|
|
||||||
|
boolean detachedVerify = api.detachedVerify(1, orgData, detachedSign);
|
||||||
|
System.out.println("det验签"+detachedVerify);
|
||||||
|
|
||||||
|
String attachedSign = api.attachedSignHsm(orgData, SM2dn);
|
||||||
|
System.out.println("att签名"+attachedSign);
|
||||||
|
|
||||||
|
boolean attachedVerify = api.attachedVerify(attachedSign.getBytes());
|
||||||
|
System.out.println("att验签"+attachedVerify);
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -40,52 +40,52 @@ public class Sample4ZS {
|
|||||||
System.out.println("SM2数据验签:"+nakedVerify1 );
|
System.out.println("SM2数据验签:"+nakedVerify1 );
|
||||||
//
|
//
|
||||||
//RSA裸签
|
//RSA裸签
|
||||||
// byte[] nakedSign2 = api.SYD_NakedSign(1, RSAdn,orgData,(byte[])null);
|
byte[] nakedSign2 = api.SYD_NakedSign(1, RSAdn,orgData,(byte[])null);
|
||||||
// boolean nakedVerify2 = api.SYD_NakedVerify(1, RSAdn,nakedSign2,orgData ,(byte[])null);
|
boolean nakedVerify2 = api.SYD_NakedVerify(1, RSAdn,nakedSign2,orgData ,(byte[])null);
|
||||||
// System.out.println("RSA数据验签:"+nakedVerify2 );
|
System.out.println("RSA数据验签:"+nakedVerify2 );
|
||||||
|
|
||||||
//detach签名
|
//detach签名
|
||||||
// for (int i = 0; i < 10; i++) {
|
|
||||||
// String detSign1 = api.detachedSignAll(4, orgData, SM2dn);
|
|
||||||
// System.out.println("SM2detach签名:"+detSign1);
|
|
||||||
// }
|
|
||||||
|
|
||||||
// boolean detV1 = api.detachedVerifyAll(4, orgData, detSign1);
|
String detSign1 = api.detachedSignAll(4, orgData, SM2dn);
|
||||||
// System.out.println("SM2detach验签:"+detV1);
|
System.out.println("SM2detach签名:"+detSign1);
|
||||||
//
|
|
||||||
//
|
|
||||||
// String detSign2= api.detachedSignAll(2, orgData, RSAdn);
|
boolean detV1 = api.detachedVerifyAll(4, orgData, detSign1);
|
||||||
// System.out.println("RSA detach签名:"+detSign2);
|
System.out.println("SM2detach验签:"+detV1);
|
||||||
// boolean detV2 = api.detachedVerifyAll(2, orgData, detSign2);
|
|
||||||
// System.out.println("RSA detach验签:"+detV2);
|
|
||||||
|
String detSign2= api.detachedSignAll(2, orgData, RSAdn);
|
||||||
|
System.out.println("RSA detach签名:"+detSign2);
|
||||||
|
boolean detV2 = api.detachedVerifyAll(2, orgData, detSign2);
|
||||||
|
System.out.println("RSA detach验签:"+detV2);
|
||||||
|
|
||||||
//attach签名
|
//attach签名
|
||||||
// String attSign1 = api.attachedSignAll(4, orgData, SM2dn);
|
String attSign1 = api.attachedSignAll(4, orgData, SM2dn);
|
||||||
// System.out.println("SM2attach签名:"+attSign1);
|
System.out.println("SM2attach签名:"+attSign1);
|
||||||
// boolean attV1 = api.attachedVerifyAll(4, attSign1);
|
boolean attV1 = api.attachedVerifyAll(4, attSign1);
|
||||||
// System.out.println("SM2attach验签:"+attV1);
|
System.out.println("SM2attach验签:"+attV1);
|
||||||
//
|
|
||||||
//
|
|
||||||
// String attSign2 = api.attachedSignAll(2, orgData, RSAdn);
|
|
||||||
// System.out.println("RSA attach签名:"+attSign2);
|
|
||||||
// boolean attV2 = api.attachedVerifyAll(2, attSign2);
|
|
||||||
// System.out.println("RSA attach验签:"+attV1);
|
|
||||||
//
|
|
||||||
// //数字信封
|
|
||||||
// RetWrap genSM2 = api.generateDEByDnAll(3, SM2dn, orgData);
|
|
||||||
// byte[] cipherKey = (byte[]) genSM2.get(SydApi.RET_CIPHER_KEY);
|
|
||||||
// System.out.println("SM4加密" + new String(cipherKey));
|
|
||||||
// RetWrap denSM2 = api.decryptDEByDNAll(3, SM2dn, cipherKey);
|
|
||||||
// byte[] oData = (byte[]) denSM2.get("oData");
|
|
||||||
// System.out.println("SM4解密:"+Util.bytes2HexString(oData));
|
|
||||||
|
|
||||||
//
|
|
||||||
// RetWrap genRSA = api.generateDEByDnAll(4, RSAdn, orgData);
|
String attSign2 = api.attachedSignAll(2, orgData, RSAdn);
|
||||||
// byte[] cipherKeyRSA = (byte[]) genRSA.get(SydApi.RET_CIPHER_KEY);
|
System.out.println("RSA attach签名:"+attSign2);
|
||||||
// System.out.println("RSA数字信封: " + new String(cipherKeyRSA));
|
boolean attV2 = api.attachedVerifyAll(2, attSign2);
|
||||||
// RetWrap denRSA = api.decryptDEByDNAll(4, RSAdn, cipherKeyRSA);
|
System.out.println("RSA attach验签:"+attV1);
|
||||||
// byte[] oDataRSA = (byte[]) denRSA.get("oData");
|
|
||||||
// System.out.println("RSA信封解密:"+Util.bytes2HexString(oDataRSA));
|
//数字信封
|
||||||
|
RetWrap genSM2 = api.generateDEByDnAll(3, SM2dn, orgData);
|
||||||
|
byte[] cipherKey = (byte[]) genSM2.get(SydApi.RET_CIPHER_KEY);
|
||||||
|
System.out.println("SM4加密" + new String(cipherKey));
|
||||||
|
RetWrap denSM2 = api.decryptDEByDNAll(3, SM2dn, cipherKey);
|
||||||
|
byte[] oData = (byte[]) denSM2.get("oData");
|
||||||
|
System.out.println("SM4解密:"+Util.bytes2HexString(oData));
|
||||||
|
|
||||||
|
|
||||||
|
RetWrap genRSA = api.generateDEByDnAll(4, RSAdn, orgData);
|
||||||
|
byte[] cipherKeyRSA = (byte[]) genRSA.get(SydApi.RET_CIPHER_KEY);
|
||||||
|
System.out.println("RSA数字信封: " + new String(cipherKeyRSA));
|
||||||
|
RetWrap denRSA = api.decryptDEByDNAll(4, RSAdn, cipherKeyRSA);
|
||||||
|
byte[] oDataRSA = (byte[]) denRSA.get("oData");
|
||||||
|
System.out.println("RSA信封解密:"+Util.bytes2HexString(oDataRSA));
|
||||||
|
|
||||||
|
|
||||||
}catch (SydApiException e){
|
}catch (SydApiException e){
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user