保留本地修改至上清分支
This commit is contained in:
commit
b26aab01a4
15
pom.xml
15
pom.xml
@ -14,8 +14,8 @@
|
||||
<vertx>3.4.2</vertx>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
<maven.compiler.encoding>UTF-8</maven.compiler.encoding>
|
||||
<maven.compiler.source>1.6</maven.compiler.source>
|
||||
<maven.compiler.target>1.6</maven.compiler.target>
|
||||
<maven.compiler.source>1.8</maven.compiler.source>
|
||||
<maven.compiler.target>1.8</maven.compiler.target>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
@ -81,6 +81,13 @@
|
||||
<version>1.0.20221215</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.apache.jmeter</groupId>
|
||||
<artifactId>ApacheJMeter_java</artifactId>
|
||||
<version>5.4.3</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
|
||||
|
||||
<dependency>
|
||||
<groupId>org.bouncycastle</groupId>
|
||||
@ -142,8 +149,8 @@
|
||||
</execution>
|
||||
</executions>
|
||||
<configuration>
|
||||
<source>1.6</source>
|
||||
<target>1.6</target>
|
||||
<source>7</source>
|
||||
<target>7</target>
|
||||
<compilerId>groovy-eclipse-compiler</compilerId>
|
||||
<verbose>true</verbose>
|
||||
<fork>true</fork>
|
||||
|
||||
210
src/main/java/com/jmeter/test/Test4ZS.java
Normal file
210
src/main/java/com/jmeter/test/Test4ZS.java
Normal file
@ -0,0 +1,210 @@
|
||||
package com.jmeter.test;
|
||||
|
||||
import com.sunyard.RetWrap;
|
||||
import com.sunyard.SydApi;
|
||||
import com.sunyard.SydApiException;
|
||||
import com.sunyard.proto.Util;
|
||||
import org.apache.jmeter.config.Arguments;
|
||||
import org.apache.jmeter.protocol.java.sampler.AbstractJavaSamplerClient;
|
||||
import org.apache.jmeter.protocol.java.sampler.JavaSamplerContext;
|
||||
import org.apache.jmeter.samplers.SampleResult;
|
||||
import racal.sunyard.main.SydApi4j;
|
||||
import racal.sunyard.main.SydApiBuilder;
|
||||
|
||||
import java.nio.charset.StandardCharsets;
|
||||
|
||||
public class Test4ZS extends AbstractJavaSamplerClient {
|
||||
|
||||
private String SM2dn ;
|
||||
private String RSAdn ;
|
||||
private String ip ;
|
||||
private String ip2 ;
|
||||
private String oData;
|
||||
private String sign;
|
||||
private byte[] orgData;
|
||||
|
||||
private int type;
|
||||
|
||||
|
||||
/**
|
||||
* 定义默认的参数,在jmeter中会自动显示在这里定义的默认参数
|
||||
* @return Arguments对象
|
||||
*/
|
||||
@Override
|
||||
public Arguments getDefaultParameters() {
|
||||
Arguments arguments = new Arguments();
|
||||
arguments.addArgument("SM2dn", "C=CN,O=CFCA OCA1,OU=YCCA,OU=Individual-2,CN=YCCA@黄金交易所@Zhuangj@1");
|
||||
arguments.addArgument("RSAdn", "C=cn,O=CFCA TEST CA,OU=NCS2,OU=Enterprises,CN=041@Z402451000010@ShanDong@00000001");
|
||||
arguments.addArgument("orgData", "12345678");
|
||||
arguments.addArgument("ip", "172.16.17.161");
|
||||
arguments.addArgument("ip2", "172.16.17.161");
|
||||
arguments.addArgument("type", "1");
|
||||
arguments.addArgument("sign", "12345678");
|
||||
return arguments;
|
||||
}
|
||||
|
||||
/**
|
||||
* 在执行测试之前执行,只执行一次,可以获取传递过来的参数,一般用来做初始化操作
|
||||
* @param context 可以获取jmeter传递过来的参数
|
||||
*/
|
||||
@Override
|
||||
public void setupTest(JavaSamplerContext context) {
|
||||
//对成员变量初始化
|
||||
SM2dn = context.getParameter("SM2dn");
|
||||
RSAdn = context.getParameter("RSAdn");
|
||||
oData = context.getParameter("orgData");
|
||||
ip = context.getParameter("ip");
|
||||
ip2 = context.getParameter("ip2");
|
||||
type = context.getIntParameter("type");
|
||||
sign = context.getParameter("sign");
|
||||
System.setProperty("com.sunyard.dnsort", "false");
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 真正的测试代码块,jmeter按照配置的逻辑执行该方法
|
||||
* @param javaSamplerContext 上下文对象,可以获取jmeter传递的参数
|
||||
* @return SampleResult对象用于封装结果
|
||||
*/
|
||||
@Override
|
||||
public SampleResult runTest(JavaSamplerContext javaSamplerContext) {
|
||||
SampleResult sr = new SampleResult();
|
||||
//设置标签
|
||||
sr.setSampleLabel("testDemo");
|
||||
//设置开始标志,否则无法统计tps等
|
||||
sr.sampleStart();
|
||||
try {
|
||||
SydApi4j.SYD_Set_Parameter_HA(ip, ip2, 8889, 1000);
|
||||
SydApi4j api = (SydApi4j) new SydApi4j();
|
||||
orgData = oData.getBytes(); //SM2裸签
|
||||
//执行业务逻辑
|
||||
switch(type){
|
||||
case 1:
|
||||
api.SYD_NakedSign(SM2dn, orgData, (byte[])null);
|
||||
sr.setResponseCodeOK();
|
||||
//sr.setResponseData(Util.encodeBase64(nakedSign1), StandardCharsets.UTF_8.displayName());
|
||||
break;
|
||||
|
||||
|
||||
case 2:
|
||||
api.SYD_NakedVerify(SM2dn, Util.decodeBase64(sign), orgData, (byte[])null) ;
|
||||
sr.setResponseCodeOK();
|
||||
//sr.setResponseData(String.valueOf(nakedVerify1), StandardCharsets.UTF_8.displayName());
|
||||
break;
|
||||
|
||||
case 3:
|
||||
//RSA裸签
|
||||
api.SYD_NakedSign(1, RSAdn,orgData,(byte[])null);
|
||||
sr.setResponseCodeOK();
|
||||
//sr.setResponseData(Util.encodeBase64(nakedSign2), StandardCharsets.UTF_8.displayName());
|
||||
break;
|
||||
|
||||
case 4:
|
||||
api.SYD_NakedVerify(1, RSAdn,Util.decodeBase64(sign),orgData ,(byte[])null);
|
||||
sr.setResponseCodeOK();
|
||||
//sr.setResponseData(String.valueOf(nakedVerify2), StandardCharsets.UTF_8.displayName());
|
||||
break;
|
||||
|
||||
case 5:
|
||||
api.detachedSign(1, orgData, SM2dn);
|
||||
sr.setResponseCodeOK();
|
||||
//sr.setResponseData(detSign1, StandardCharsets.UTF_8.displayName());
|
||||
break;
|
||||
|
||||
case 6:
|
||||
api.detachedVerify(1, orgData, sign);
|
||||
sr.setResponseCodeOK();
|
||||
//sr.setResponseData(String.valueOf(detV1), StandardCharsets.UTF_8.displayName());
|
||||
break;
|
||||
|
||||
case 7:
|
||||
api.detachedSign(2,1, orgData, RSAdn);
|
||||
sr.setResponseCodeOK();
|
||||
//sr.setResponseData(detSign2, StandardCharsets.UTF_8.displayName());
|
||||
break;
|
||||
|
||||
case 8:
|
||||
api.detachedVerify(2,2, orgData, sign);
|
||||
sr.setResponseCodeOK();
|
||||
//sr.setResponseData(String.valueOf(detV2), StandardCharsets.UTF_8.displayName());
|
||||
break;
|
||||
|
||||
case 9:
|
||||
api.attachedSignHsm(orgData, SM2dn);
|
||||
sr.setResponseCodeOK();
|
||||
//sr.setResponseData(attSign1, StandardCharsets.UTF_8.displayName());
|
||||
break;
|
||||
|
||||
case 10:
|
||||
api.attachedVerify( sign.getBytes());
|
||||
sr.setResponseCodeOK();
|
||||
// sr.setResponseData(String.valueOf(attV1), StandardCharsets.UTF_8.displayName());
|
||||
break;
|
||||
|
||||
case 11:
|
||||
api.attachedSignRSAHsm(2, orgData, RSAdn);
|
||||
sr.setResponseCodeOK();
|
||||
// sr.setResponseData(attSign2, StandardCharsets.UTF_8.displayName());
|
||||
break;
|
||||
|
||||
case 12:
|
||||
api.attachedVerifyRSA(2, sign);
|
||||
sr.setResponseCodeOK();
|
||||
// sr.setResponseData(String.valueOf(attV2), StandardCharsets.UTF_8.displayName());
|
||||
break;
|
||||
|
||||
case 13:
|
||||
api.generateDE(SM2dn.getBytes(), 3, 1, orgData);
|
||||
// byte[] cipherKey = (byte[]) genSM2.get(SydApi.RET_CIPHER_KEY);
|
||||
sr.setResponseCodeOK();
|
||||
// sr.setResponseData(new String(cipherKey), StandardCharsets.UTF_8.displayName());
|
||||
break;
|
||||
|
||||
case 14:
|
||||
api.decryptDE(true, 1, SM2dn.getBytes(), sign);;
|
||||
// byte[] oData = (byte[]) denSM2.get("oData");
|
||||
sr.setResponseCodeOK();
|
||||
// sr.setResponseData(new String(oData), StandardCharsets.UTF_8.displayName());
|
||||
break;
|
||||
|
||||
|
||||
case 15:
|
||||
api. generateDE(RSAdn.getBytes(), 4, 1, orgData);
|
||||
// byte[] cipherKeyRSA = (byte[]) genRSA.get(SydApi.RET_CIPHER_KEY);
|
||||
sr.setResponseCodeOK();
|
||||
//sr.setResponseData(new String(cipherKeyRSA), StandardCharsets.UTF_8.displayName());
|
||||
break;
|
||||
|
||||
case 16:
|
||||
api.decryptDERSA(true, 1, RSAdn.getBytes(), sign);
|
||||
// byte[] oDataRSA = (byte[]) denRSA.get("oData");
|
||||
sr.setResponseCodeOK();
|
||||
//sr.setResponseData(new String(oDataRSA), StandardCharsets.UTF_8.displayName());
|
||||
break;
|
||||
|
||||
default:
|
||||
sr.setResponseCodeOK();
|
||||
sr.setResponseData("请选择测试组", StandardCharsets.UTF_8.displayName());
|
||||
break;
|
||||
}
|
||||
sr.setSuccessful(true);
|
||||
}catch (SydApiException e){
|
||||
e.printStackTrace();
|
||||
sr.setResponseCode(String.valueOf(e.getRetCode()));
|
||||
sr.setResponseData(e.getMessage(), StandardCharsets.UTF_8.displayName());
|
||||
sr.setSuccessful(false);
|
||||
}finally {
|
||||
sr.sampleEnd();
|
||||
}
|
||||
return sr;
|
||||
}
|
||||
|
||||
/**
|
||||
* 测试完成后执行,一般用于关闭资源
|
||||
* @param context 上下文对象,可用于获取jmeter传递的参数
|
||||
*/
|
||||
@Override
|
||||
public void teardownTest(JavaSamplerContext context) {
|
||||
System.runFinalization();
|
||||
}
|
||||
}
|
||||
@ -172,5 +172,7 @@ public interface SydCertApi {
|
||||
|
||||
|
||||
String getCertByDn(String dn) throws UnsupportedEncodingException;
|
||||
|
||||
String getCertByDn(String dn,int type) throws UnsupportedEncodingException;
|
||||
public String getCertByDn(byte[] dnBytes);
|
||||
}
|
||||
|
||||
@ -240,7 +240,7 @@ public interface SydGenApi {
|
||||
*/
|
||||
RetWrap generateDEByDn(String certSerial, byte[] oData);
|
||||
|
||||
RetWrap generateDEByDn(int alg,String certSerial, byte[] oData);
|
||||
RetWrap generateDEByDnRSA(int alg,String certSerial, byte[] oData);
|
||||
|
||||
/**
|
||||
* 产生对称密钥,通过公钥加密生成网联格式的数字信封。
|
||||
@ -323,7 +323,7 @@ public interface SydGenApi {
|
||||
* orgCode 如果有机构码的话会返回机构码
|
||||
*/
|
||||
RetWrap decryptDEByDN(String certSerial, byte[] pCipherKey);
|
||||
RetWrap decryptDEByDN(int alg,String certSerial, byte[] pCipherKey);
|
||||
RetWrap decryptDEByDNRSA(int alg,String certSerial, byte[] pCipherKey);
|
||||
/**
|
||||
* 接收用私钥解密数字信封,还原对称密钥。
|
||||
*
|
||||
|
||||
@ -154,7 +154,7 @@ public interface SydAttachedSVApi {
|
||||
* @return
|
||||
* 符合PKCS7标准的签名结果
|
||||
*/
|
||||
String attachedSign(int rFlag,byte[] orgData, String sCertDN) throws UnsupportedEncodingException;
|
||||
String attachedSignRSA(int rFlag,byte[] orgData, String sCertDN) throws UnsupportedEncodingException;
|
||||
|
||||
/**
|
||||
* 带公钥证书与原始数据的数字签名验签(遵循 PKCS#7)
|
||||
@ -172,7 +172,7 @@ public interface SydAttachedSVApi {
|
||||
* @param sign 已签名数据
|
||||
* @return true 验签通过 false 验签失败
|
||||
*/
|
||||
boolean attachedVerify(int rFlag,String sign);
|
||||
boolean attachedVerifyRSA(int rFlag,String sign);
|
||||
|
||||
|
||||
boolean attachedVerify(byte[] sign);
|
||||
|
||||
183
src/main/java/com/sunyard/util/FrameCache.java
Normal file
183
src/main/java/com/sunyard/util/FrameCache.java
Normal file
@ -0,0 +1,183 @@
|
||||
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;
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
74
src/test/java/sample/Sample4HY.java
Normal file
74
src/test/java/sample/Sample4HY.java
Normal file
@ -0,0 +1,74 @@
|
||||
package sample;
|
||||
|
||||
import com.sunyard.RetWrap;
|
||||
import com.sunyard.SydApi;
|
||||
import com.sunyard.SydApiException;
|
||||
import com.sunyard.proto.Util;
|
||||
import racal.sunyard.main.SydApi4j;
|
||||
import racal.sunyard.main.SydApiBuilder;
|
||||
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
public class Sample4HY {
|
||||
private static final String SM2dn = "C=cn,O=CFCA TEST OCA1,OU=Local RA,OU=Organizational-1,CN=041@Z8000000001938231GX0@8000000001938231GX0@00000001";
|
||||
private static final String SM2dn2 = "C=CN,O=CFCA OCA1,OU=YCCA,OU=Individual-2,CN=YCCA@黄金交易所@Zhuangj@1" ;
|
||||
|
||||
|
||||
private static final byte[] orgData = new byte[ 1*1024];
|
||||
|
||||
public static void main(String[] args) {
|
||||
//调试模式(控制台会打印发送报文)
|
||||
System.setProperty("com.sunyard.sydapi4j.debug", "true");
|
||||
//证书是否反序校验
|
||||
//System.setProperty("com.sunyard.dnsort", "false");
|
||||
//主备模式连接
|
||||
SydApi4j.SYD_Set_Parameter_HA("172.16.17.1", "172.16.17.16", 8889, 1000);
|
||||
SydApi4j api = (SydApi4j) new SydApi4j();
|
||||
//设置连接
|
||||
// SydApiBuilder builder = new SydApiBuilder().setIp("192.168.0.100");
|
||||
// SydApi4j api = (SydApi4j) builder.build();
|
||||
try {
|
||||
|
||||
// SM2裸签
|
||||
byte[] nakedSign1 = api.SYD_NakedSign(orgData, SM2dn2);
|
||||
System.out.println("SM2数据裸签:"+ Util.encodeBase64(nakedSign1));
|
||||
|
||||
boolean nakedVerify1 = api.SYD_NakedVerify(orgData, nakedSign1, SM2dn2);
|
||||
System.out.println("SM2数据验签:"+nakedVerify1 );
|
||||
|
||||
|
||||
// //数字信封
|
||||
// RetWrap genSM2 = api.generateDEByDn( SM2dn2, orgData);
|
||||
// byte[] cipherKey = (byte[]) genSM2.get(SydApi.RET_CIPHER_KEY);
|
||||
// System.out.println("SM2数字信封: " + new String(cipherKey));
|
||||
// RetWrap denSM2 = api.decryptDEByDN( SM2dn2, cipherKey);
|
||||
// byte[] oData = (byte[]) denSM2.get("oData");
|
||||
// System.out.println("SM2信封解密:"+Util.bytes2HexString(oData));
|
||||
//
|
||||
//
|
||||
// String aa ="MEUCIQD3ZW+ReFjSbkPx2SEm3R8SwC4ke8ZllgGJBXEp8aSJsAIgUUEVqWQtbDPitbJQec5+71gCU3e3OBNwdL0EYoKId4k=";
|
||||
// String oData2 ="test123";
|
||||
// boolean nakedVerify2 = api.SYD_NakedVerify(oData2.getBytes(), Util.decodeBase64(aa), SM2dn);
|
||||
// System.out.println("SM2数据验签:"+nakedVerify2 );
|
||||
|
||||
|
||||
// String certByDn = api.getCertByDn(SM2dn2, 0);
|
||||
// System.out.println(certByDn);
|
||||
//
|
||||
// Pattern pattern = Pattern.compile("-----BEGIN CERTIFICATE-----|-----END CERTIFICATE-----");
|
||||
// Matcher matcher = pattern.matcher(certByDn);
|
||||
// String dealCert = matcher.replaceAll("").trim();
|
||||
// System.out.println(dealCert);
|
||||
|
||||
|
||||
}catch (SydApiException e){
|
||||
e.printStackTrace();
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
97
src/test/java/sample/Sample4ZS.java
Normal file
97
src/test/java/sample/Sample4ZS.java
Normal file
@ -0,0 +1,97 @@
|
||||
package sample;
|
||||
|
||||
import com.sunyard.RetWrap;
|
||||
import com.sunyard.SydApi;
|
||||
import com.sunyard.SydApiException;
|
||||
import com.sunyard.proto.Util;
|
||||
import racal.sunyard.main.SydApi4j;
|
||||
import racal.sunyard.main.SydApiBuilder;
|
||||
|
||||
public class Sample4ZS {
|
||||
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) {
|
||||
//调试模式(控制台会打印发送报文)
|
||||
System.setProperty("com.sunyard.sydapi4j.debug", "true");
|
||||
//证书是否反序校验
|
||||
//System.setProperty("com.sunyard.dnsort", "false");
|
||||
String ip = "172.16.17.1";
|
||||
String ip2 = "172.16.17.161";
|
||||
|
||||
//主备模式连接
|
||||
SydApi4j.SYD_Set_Parameter_HA(ip, ip2, 8889, 1000);
|
||||
SydApi4j api = (SydApi4j) new SydApi4j();
|
||||
//设置连接
|
||||
// SydApiBuilder builder = new SydApiBuilder().setIp("172.16.17.161");
|
||||
// SydApi4j api = (SydApi4j) builder.build();
|
||||
try {
|
||||
long startTime = System.currentTimeMillis(); //获取开始时间
|
||||
// //SM2裸签
|
||||
byte[] nakedSign1 = api.SYD_NakedSignAll(4,orgData, SM2dn);
|
||||
System.out.println("SM2数据裸签:"+ Util.encodeBase64(nakedSign1));
|
||||
//
|
||||
// long endTime = System.currentTimeMillis(); //获取结束时间
|
||||
// System.out.println("程序运行时间:" + (endTime - startTime) + "ms");
|
||||
boolean nakedVerify1 = api.SYD_NakedVerifyAll(4,orgData, nakedSign1, SM2dn);
|
||||
System.out.println("SM2数据验签:"+nakedVerify1 );
|
||||
//
|
||||
//RSA裸签
|
||||
// byte[] nakedSign2 = api.SYD_NakedSign(1, RSAdn,orgData,(byte[])null);
|
||||
// boolean nakedVerify2 = api.SYD_NakedVerify(1, RSAdn,nakedSign2,orgData ,(byte[])null);
|
||||
// System.out.println("RSA数据验签:"+nakedVerify2 );
|
||||
|
||||
// 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);
|
||||
// System.out.println("SM2detach验签:"+detV1);
|
||||
//
|
||||
//
|
||||
// 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签名
|
||||
// String attSign1 = api.attachedSignAll(4, orgData, SM2dn);
|
||||
// System.out.println("SM2attach签名:"+attSign1);
|
||||
// boolean attV1 = api.attachedVerifyAll(4, attSign1);
|
||||
// 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);
|
||||
// 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){
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@ -15,8 +15,12 @@ public class Shangqing {
|
||||
|
||||
// 测试数据
|
||||
private String uid = "8012";
|
||||
private String dn = "C=CN,O=CFCA OCA1,OU=YCCA,OU=Individual-2,CN=YCCA@黄金交易所@Zhuangj@1";
|
||||
private byte[] orgData = new byte[2 * 1024 * 1024];
|
||||
private String dn = "C=CN,ST=ZJ,L=HZ,O=sunyard,OU=test1,CN=test1";
|
||||
private String SM2dn = "C=CN,O=CFCA OCA1,OU=YCCA,OU=Individual-2,CN=YCCA@黄金交易所@Zhuangj@1";
|
||||
|
||||
|
||||
private String RSA ="C=cn,O=CFCA TEST CA,OU=NCS2,OU=Enterprises,CN=041@Z402451000010@ShanDong@00000001";
|
||||
private byte[] orgData = new byte[10*1024];
|
||||
|
||||
@Before
|
||||
public void before() {
|
||||
@ -72,16 +76,20 @@ public class Shangqing {
|
||||
*/
|
||||
@Test
|
||||
public void dm(){
|
||||
// 生成数字信封
|
||||
RetWrap retWrap = api.generateDEByDn(dn, orgData );
|
||||
byte[] cipherKey = (byte[]) retWrap.get(SydApi.RET_CIPHER_KEY);
|
||||
System.out.println("数字信封: " + new String(cipherKey));
|
||||
// // 生成数字信封
|
||||
// RetWrap retWrap = api.generateDEByDn(SM2dn, orgData );
|
||||
// byte[] cipherKey = (byte[]) retWrap.get(SydApi.RET_CIPHER_KEY);
|
||||
// System.out.println("数字信封: " + new String(cipherKey));
|
||||
//
|
||||
// // 解密数字信封
|
||||
// RetWrap retWrap1 = api.decryptDEByDN(SM2dn, cipherKey);
|
||||
// byte[] oData = (byte[]) retWrap1.get("oData");
|
||||
//
|
||||
//
|
||||
// Assert.assertArrayEquals( oData, orgData );
|
||||
|
||||
// 解密数字信封
|
||||
RetWrap retWrap1 = api.decryptDEByDN(dn, cipherKey);
|
||||
byte[] oData = (byte[]) retWrap1.get("oData");
|
||||
|
||||
Assert.assertArrayEquals( oData, orgData );
|
||||
String s = api.GenRandom(8);
|
||||
System.out.println(s);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -1,2 +1,199 @@
|
||||
package sample;public class Test4Nongxin {
|
||||
package sample;
|
||||
|
||||
import cn.hutool.core.codec.Base64;
|
||||
import com.sunyard.SydApi;
|
||||
import com.sunyard.SydApiException;
|
||||
import com.sunyard.cert.X509;
|
||||
import com.sunyard.proto.Util;
|
||||
import com.sunyard.util.ASN1Util;
|
||||
import com.sunyard.util.SYMUtil;
|
||||
import org.junit.Test;
|
||||
import racal.sunyard.main.SydApi4j;
|
||||
import racal.sunyard.main.SydApiBuilder;
|
||||
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.util.List;
|
||||
|
||||
public class Test4Nongxin {
|
||||
|
||||
private static final String SM2dn = "C=CN,O=CFCA OCA1,OU=YCCA,OU=Individual-2,CN=YCCA@黄金交易所@Zhuangj@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[ 10*1024 ];
|
||||
private static final byte[] orgDataBig = new byte[ 10*1024 ];
|
||||
public static void main(String[] args) {
|
||||
//System.setProperty("com.sunyard.sydapi4j.debug", "true");
|
||||
//设置连接
|
||||
SydApiBuilder builder = new SydApiBuilder().setIp("172.16.17.161");
|
||||
SydApi4j api = (SydApi4j) builder.build();
|
||||
try {
|
||||
//SM2裸签
|
||||
byte[] nakedSign1 = api.SYD_NakedSignAll(4,orgData, SM2dn);
|
||||
System.out.println("SM2大数据裸签:"+ Util.bytes2HexString(nakedSign1));
|
||||
boolean nakedVerify1 = api.SYD_NakedVerifyAll(4,orgData, nakedSign1, SM2dn);
|
||||
System.out.println("SM2大数据验签:"+nakedVerify1 );
|
||||
|
||||
//RSA裸签
|
||||
byte[] nakedSign2 = api.SYD_NakedSignAll(1,orgData, RSAdn);
|
||||
System.out.println("RSA大数据裸签:"+ Util.bytes2HexString(nakedSign2));
|
||||
boolean nakedVerify2 = api.SYD_NakedVerifyAll(1,orgData, nakedSign2, RSAdn);
|
||||
System.out.println("RSA大数据验签:"+nakedVerify2 );
|
||||
|
||||
|
||||
byte[] nakedSign3 = api.SYD_NakedSignAll(4,orgData, SM2dn);
|
||||
System.out.println("SM2裸签:"+ Util.bytes2HexString(nakedSign3));
|
||||
boolean nakedVerify3 = api.SYD_NakedVerifyAll(4,orgData, nakedSign3, SM2dn);
|
||||
System.out.println("SM2验签:"+nakedVerify3 );
|
||||
|
||||
byte[] nakedSign4 = api.SYD_NakedSignAll(2,orgData, RSAdn);
|
||||
System.out.println("RSA裸签:"+ Util.bytes2HexString(nakedSign4));
|
||||
boolean nakedVerify4 = api.SYD_NakedVerifyAll(2,orgData, nakedSign4, RSAdn);
|
||||
System.out.println("RSA验签:"+nakedVerify4 );
|
||||
|
||||
|
||||
String s = api.detachedSignAll(4, orgData, SM2dn);
|
||||
System.out.println("SM2detach签名:"+s);
|
||||
boolean b = api.detachedVerifyAll(4, orgData, s);
|
||||
System.out.println("SM2detach验签:"+b);
|
||||
|
||||
|
||||
String sde = api.detachedSignAll(4, orgDataBig, SM2dn);
|
||||
System.out.println("SM2detach签名:"+sde);
|
||||
boolean bde = api.detachedVerifyAll(4, orgDataBig, sde);
|
||||
System.out.println("SM2detach验签:"+bde);
|
||||
|
||||
|
||||
String rsa = api.detachedSignAll(2, orgData, RSAdn);
|
||||
System.out.println("RSA detach签名:"+rsa);
|
||||
boolean br = api.detachedVerifyAll(2, orgData, rsa);
|
||||
System.out.println("RSA detach验签:"+br);
|
||||
|
||||
|
||||
String det = api.detachedSignAll(3, orgDataBig, RSAdn);
|
||||
System.out.println("RSA大数据detach签名:"+det);
|
||||
boolean boo = api.detachedVerifyAll(3, orgDataBig, det);
|
||||
System.out.println("RSA大数据detach验签:"+boo);
|
||||
|
||||
|
||||
} catch (SydApiException e) {
|
||||
throw new RuntimeException(e);
|
||||
} finally {
|
||||
api.disconnect();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDetach() throws UnsupportedEncodingException {
|
||||
System.setProperty("com.sunyard.sydapi4j.debug", "true");
|
||||
//设置连接
|
||||
SydApiBuilder builder = new SydApiBuilder().setIp("172.16.17.161").setPort(8889).setTimeout(3000);
|
||||
SydApi4j api = (SydApi4j) builder.build();
|
||||
String dnn="C=CN,O=CFCA OCA1,OU=TPC-S3,OU=Organizational-2,CN=ARCU54H100000024";
|
||||
|
||||
String plain="<?xml version=\"1.0\" encoding=\"utf-8\"?><SignData><TradeType authLevel=\"0\" name=\"银行账号转账\">tran/acctTran</TradeType><Fields><PAYER_ACCT_NO name=\"付款账号:\">6217788300130014042</PAYER_ACCT_NO><RCV_ACCT_NO name=\"收款账号:\">6200548800010650170</RCV_ACCT_NO><RCV_ACCT_NAME name=\"收款方账户名称:\">测试</RCV_ACCT_NAME><TRAN_AMT name=\"转账金额:\">60001</TRAN_AMT></Fields></SignData>";
|
||||
|
||||
String signed = "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";
|
||||
|
||||
boolean boo = api.detachedVerifyAll(3, plain.getBytes(), signed);
|
||||
System.out.println("RSA大数据detach验签:"+boo);
|
||||
plain.getBytes("UTF-8");
|
||||
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void p1Test() throws UnsupportedEncodingException {
|
||||
|
||||
// 调试模式
|
||||
// System.setProperty("com.sunyard.sydapi4j.debug", "true");
|
||||
// 建立连接
|
||||
String certDn ="C=CN,O=Sunyard,OU=8001,CN=8001";
|
||||
String DN = "C=CN,OU=eves,CN=jindiancloud";
|
||||
String Sm2DN="C=CN,O=CFCA OCA1,OU=YCCA,OU=Individual-2,CN=YCCA@黄金交易所@Zhuangj@1";
|
||||
//设置连接
|
||||
SydApiBuilder builder = new SydApiBuilder().setIp("172.16.17.161").setPort(8889).setTimeout(3000);
|
||||
SydApi4j api = (SydApi4j) builder.build();
|
||||
byte[] oData = new byte[10];
|
||||
//p1签名
|
||||
byte[] sign = api.SYD_NakedSignAll(4,oData, Sm2DN);
|
||||
// System.out.println("p1签名:"+ Util.bytes2HexString(sign));
|
||||
String base64Sign = Util.encodeBase64(sign);
|
||||
System.out.println("p1签名:"+ base64Sign);
|
||||
|
||||
// boolean pass = api.SYD_NakedVerifyAll(4,oData,sign, Sm2DN);
|
||||
// System.out.println("验签结果 " + pass);
|
||||
//
|
||||
// String certByDn = api.getCertByDn(Sm2DN,0);
|
||||
// X509 x509 = api.GetX509CertInfo(certByDn);
|
||||
// byte[] pubKey = x509.getPubKey();
|
||||
// System.out.println("公钥:"+Util.bytes2HexString(pubKey));
|
||||
//
|
||||
// String s = api.SYD_SM2_Sign_HA("8012", 1, pubKey, oData);
|
||||
// System.out.println("公钥签名:"+s);
|
||||
//
|
||||
// hihi
|
||||
|
||||
String sign2 ="svVyVaA6Og8QCWagGBdohDuIh/Lhb34Lv6Kc+3OE0GVVPdYxi9+zM6IBq6ZxEjuyIRPnxy1GCdye5I9hEOqZuQ==";
|
||||
byte[] bytes = SYMUtil.base64Sign2DerSign(sign2);
|
||||
System.out.println(Util.bytes2HexString(bytes));
|
||||
//byte[] bytes2 = SYMUtil.base64SignAsDerSign(sign2);
|
||||
byte[] bytes2 = SYMUtil.base64SignAsDerSign(Util.encodeBase64(bytes));
|
||||
System.out.println(Util.bytes2HexString(bytes2));
|
||||
|
||||
List<String> allCert = api.getAllCert();
|
||||
System.out.println(allCert);
|
||||
|
||||
// String Data= "<MainBody>\n" +
|
||||
// " <MsgId>\n" +
|
||||
// " <Id>400027000000000202305300000000931</Id>\n" +
|
||||
// " <CreDtTm>2023-05-30T18:04:12</CreDtTm>\n" +
|
||||
// " </MsgId>\n" +
|
||||
// " <ReqMsgInf><NES002><MsgId><Id>400027000000000202305300000000931</Id><CreDtTm>2023-05-30T18:06:46</CreDtTm></MsgId><DwrInf><AppBrId>400027</AppBrId><NoDrtPtcptInf><Name>日照德润建筑工程有限公司</Name><SocCode>91371100773158280D</SocCode><DistTp>DT02</DistTp><BrAcctInf><AcctName>日照德润建筑工程有限公司</AcctName><Acct>803011301421013273</Acct><OpenBrId>000041816</OpenBrId></BrAcctInf></NoDrtPtcptInf></DwrInf><SgntrMk><PrxySgntr>PS01</PrxySgntr><PtcptSgntr>3300000009831853</PtcptSgntr></SgntrMk><DraftBasicInf><CdNo>731346340004320230530000114152</CdNo><CdRange>000000000001,000002000000</CdRange><CdAmt Ccy=\"CNY\">20000.00</CdAmt><StdAmt Ccy=\"CNY\">0.01</StdAmt></DraftBasicInf><BusiInf><Dt>2023-05-30</Dt><BusiCategory>BC02</BusiCategory><UcondlConsgnmtMrk>CC00</UcondlConsgnmtMrk></BusiInf></NES002></ReqMsgInf>\n" +
|
||||
// " <AutoSend>0</AutoSend>\n" +
|
||||
// " <DraftBasicInf>\n" +
|
||||
// " <CdNo>731346340004320230530000114152</CdNo>\n" +
|
||||
// " <CdRange>000000000001,000002000000</CdRange>\n" +
|
||||
// " <CdAmt Ccy=\"CNY\">20000.00</CdAmt>\n" +
|
||||
// " <StdAmt Ccy=\"CNY\">0.01</StdAmt>\n" +
|
||||
// " </DraftBasicInf>\n" +
|
||||
// " <DraftInf>\n" +
|
||||
// " <CdMedia>ME02</CdMedia>\n" +
|
||||
// " <CdType>AC02</CdType>\n" +
|
||||
// " <CdSource>CS03</CdSource>\n" +
|
||||
// " <IssDt>2023-05-30</IssDt>\n" +
|
||||
// " <DueDt>2023-05-31</DueDt>\n" +
|
||||
// " </DraftInf>\n" +
|
||||
// "</MainBody>";
|
||||
//
|
||||
// String Data2 ="";
|
||||
// String pk= "A0IABNTSZikiGRMscOVhIvGntbsvhz+fe8y/WqFSc10IwiAs6vuAYaN/RJ5/cFHDsC08I+vJOiiRFZPRe3vgAHad8Hs=";
|
||||
// String sign2 ="MEYCIQDiIjaN/OXnEwHEIoTVR8ADB47FzEI4kb9VVIe0au1gVgIhAKNqfCeu6NAs9bFF1IrJvUDYvZTKRIM1OkKDQU8trSfY";
|
||||
// boolean verify_ha = api.SYD_SM2_Verify_HA(1, Util.decodeBase64(pk), Data.getBytes(), sign2);
|
||||
// System.out.println("公钥验签2:"+verify_ha);
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
@Test
|
||||
public void test4SLS() throws UnsupportedEncodingException {
|
||||
System.setProperty("com.sunyard.sydapi4j.debug", "true");
|
||||
String DN = "C=CN,OU=eves,CN=jindiancloud";
|
||||
//设置连接
|
||||
SydApiBuilder builder = new SydApiBuilder().setIp("172.16.17.161").setPort(8889).setTimeout(3000);
|
||||
SydApi4j api = (SydApi4j) builder.build();
|
||||
|
||||
String Data ="{\"head\":{\"SrcCode\":\"C00000000002\",\"SigCerNo\":\"0000000000000001\",\"ReqTime\":\"20221115175955\",\"TranCode\":\"T1001\",\"ReqSeqNo\":\"C1002003000120221103101855000001\",\"DesCode\":\"B00000000005\"},\"body\":{\"AccNo\":\"76690188000100128\",\"RequestCode\":\"B00000000005\",\"ReceiveCode\":\"C00000000002\",\"CurrCod\":\"CNY\",\"PushEves\":\"1\",\"VouDate\":\"20221012\",\"CallUrl\":\"192.44.2.97:31003\",\"IsStore\":\"1\",\"VouNo\":\"20221103031\",\"AntiTamperSign\":\"7e0ef4b1d7cac4c15b070af3fdbb574eed51e960b998a8c67db8287691d14e74\"}}";
|
||||
String base64Data="eyJoZWFkIjp7IlNyY0NvZGUiOiJDMDAwMDAwMDAwMDIiLCJTaWdDZXJObyI6IjAwMDAwMDAwMDAwMDAwMDEiLCJSZXFUaW1lIjoiMjAyMjExMTUxNzU5NTUiLCJUcmFuQ29kZSI6IlQxMDAxIiwiUmVxU2VxTm8iOiJDMTAwMjAwMzAwMDEyMDIyMTEwMzEwMTg1NTAwMDAwMSIsIkRlc0NvZGUiOiJCMDAwMDAwMDAwMDUifSwiYm9keSI6eyJBY2NObyI6Ijc2NjkwMTg4MDAwMTAwMTI4IiwiUmVxdWVzdENvZGUiOiJCMDAwMDAwMDAwMDUiLCJSZWNlaXZlQ29kZSI6IkMwMDAwMDAwMDAwMiIsIkN1cnJDb2QiOiJDTlkiLCJQdXNoRXZlcyI6IjEiLCJWb3VEYXRlIjoiMjAyMjEwMTIiLCJDYWxsVXJsIjoiMTkyLjQ0LjIuOTc6MzEwMDMiLCJJc1N0b3JlIjoiMSIsIlZvdU5vIjoiMjAyMjExMDMwMzEiLCJBbnRpVGFtcGVyU2lnbiI6IjdlMGVmNGIxZDdjYWM0YzE1YjA3MGFmM2ZkYmI1NzRlZWQ1MWU5NjBiOTk4YThjNjdkYjgyODc2OTFkMTRlNzQifX0=";
|
||||
System.out.println("原数据base64:"+Util.encodeBase64(Data.getBytes()));
|
||||
|
||||
String sign ="rNHjcF+QQezzrbtYRtBKSe7zyr304vtTBb+3rZHVYrzHHlW1DI6cDOdjyCdFkYQHiFsz/XfgrUIZqHA1kMgjUg==";
|
||||
byte[] decode64sign = SYMUtil.base64Sign2DerSign(sign);
|
||||
|
||||
boolean pass = api.SYD_NakedVerifyAll(4,Data.getBytes() ,decode64sign, DN);
|
||||
System.out.println("验签结果:"+pass);
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
29
src/test/java/sample/Test4SLS.java
Normal file
29
src/test/java/sample/Test4SLS.java
Normal file
@ -0,0 +1,29 @@
|
||||
package sample;
|
||||
|
||||
import com.sunyard.proto.Util;
|
||||
import com.sunyard.util.SYMUtil;
|
||||
import racal.sunyard.main.SydApi4j;
|
||||
import racal.sunyard.main.SydApiBuilder;
|
||||
|
||||
public class Test4SLS {
|
||||
public static void main(String[] args) {
|
||||
System.setProperty("com.sunyard.sydapi4j.debug", "true");
|
||||
String DN = "C=CN,OU=eves,CN=jindiancloud";
|
||||
//设置连接
|
||||
SydApiBuilder builder = new SydApiBuilder().setIp("172.16.17.161").setPort(8889).setTimeout(3000);
|
||||
SydApi4j api = (SydApi4j) builder.build();
|
||||
|
||||
String Data ="{\"head\":{\"SrcCode\":\"C00000000002\",\"SigCerNo\":\"0000000000000001\",\"ReqTime\":\"20221115175955\",\"TranCode\":\"T1001\",\"ReqSeqNo\":\"C1002003000120221103101855000001\",\"DesCode\":\"B00000000005\"},\"body\":{\"AccNo\":\"76690188000100128\",\"RequestCode\":\"B00000000005\",\"ReceiveCode\":\"C00000000002\",\"CurrCod\":\"CNY\",\"PushEves\":\"1\",\"VouDate\":\"20221012\",\"CallUrl\":\"192.44.2.97:31003\",\"IsStore\":\"1\",\"VouNo\":\"20221103031\",\"AntiTamperSign\":\"7e0ef4b1d7cac4c15b070af3fdbb574eed51e960b998a8c67db8287691d14e74\"}}";
|
||||
String base64Data="eyJoZWFkIjp7IlNyY0NvZGUiOiJDMDAwMDAwMDAwMDIiLCJTaWdDZXJObyI6IjAwMDAwMDAwMDAwMDAwMDEiLCJSZXFUaW1lIjoiMjAyMjExMTUxNzU5NTUiLCJUcmFuQ29kZSI6IlQxMDAxIiwiUmVxU2VxTm8iOiJDMTAwMjAwMzAwMDEyMDIyMTEwMzEwMTg1NTAwMDAwMSIsIkRlc0NvZGUiOiJCMDAwMDAwMDAwMDUifSwiYm9keSI6eyJBY2NObyI6Ijc2NjkwMTg4MDAwMTAwMTI4IiwiUmVxdWVzdENvZGUiOiJCMDAwMDAwMDAwMDUiLCJSZWNlaXZlQ29kZSI6IkMwMDAwMDAwMDAwMiIsIkN1cnJDb2QiOiJDTlkiLCJQdXNoRXZlcyI6IjEiLCJWb3VEYXRlIjoiMjAyMjEwMTIiLCJDYWxsVXJsIjoiMTkyLjQ0LjIuOTc6MzEwMDMiLCJJc1N0b3JlIjoiMSIsIlZvdU5vIjoiMjAyMjExMDMwMzEiLCJBbnRpVGFtcGVyU2lnbiI6IjdlMGVmNGIxZDdjYWM0YzE1YjA3MGFmM2ZkYmI1NzRlZWQ1MWU5NjBiOTk4YThjNjdkYjgyODc2OTFkMTRlNzQifX0=";
|
||||
System.out.println("原数据base64:"+Util.encodeBase64(Data.getBytes()));
|
||||
|
||||
String sign ="rNHjcF+QQezzrbtYRtBKSe7zyr304vtTBb+3rZHVYrzHHlW1DI6cDOdjyCdFkYQHiFsz/XfgrUIZqHA1kMgjUg==";
|
||||
byte[] decode64sign = SYMUtil.base64Sign2DerSign(sign);
|
||||
|
||||
boolean pass = api.SYD_NakedVerifyAll(4,Data.getBytes() ,decode64sign, DN);
|
||||
System.out.println("验签结果:"+pass);
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@ -28,17 +28,4 @@ public class TestDE {
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void de4K_rsa_aes() {
|
||||
byte[] data = new byte[3 * 1024];
|
||||
RetWrap ret = api.generateDEByDn(0, rsa, data);
|
||||
byte[] cipherKey = (byte[]) ret.get(SydApi.RET_CIPHER_KEY);
|
||||
|
||||
System.out.println("cipherKey=" + new String(cipherKey));
|
||||
|
||||
ret = api.decryptDEByDN(0, rsa, cipherKey);
|
||||
byte[] oData = (byte[]) ret.get("oData");
|
||||
|
||||
Assert.assertArrayEquals(data, oData);
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user