loadrunner 脚本
This commit is contained in:
parent
dd63df5abb
commit
50178ef483
66
kit.json
Normal file
66
kit.json
Normal file
@ -0,0 +1,66 @@
|
|||||||
|
{
|
||||||
|
"vars": {
|
||||||
|
"version": "git()",
|
||||||
|
"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"
|
||||||
|
}, {
|
||||||
|
"cmd" : "mvn dependency:copy-dependencies -DincludeScope=runtime -DoutputDirectory=%out_path%/jar/dependences",
|
||||||
|
"check": "BUILD SUCCESS"
|
||||||
|
}],
|
||||||
|
"gen" : [{
|
||||||
|
"cmd" : "dproto"
|
||||||
|
}],
|
||||||
|
"build": [
|
||||||
|
{
|
||||||
|
"cmd": "mvn package -DskipTests",
|
||||||
|
"check": "BUILD SUCCESS"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"func": "rename",
|
||||||
|
"from": "%target_f1%",
|
||||||
|
"to": "%target_t1%"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"func": "rename",
|
||||||
|
"from": "%target_f2%",
|
||||||
|
"to": "%target_t2%"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"func": "zip",
|
||||||
|
"from": "%out_path%",
|
||||||
|
"to": "%out_path%/sydapi-%version%.zip"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
|
||||||
|
}
|
||||||
@ -58,8 +58,8 @@ interface SydAttachedSVApi {
|
|||||||
* @param orgData 要签名的信息
|
* @param orgData 要签名的信息
|
||||||
* @return 签名结果
|
* @return 签名结果
|
||||||
*/
|
*/
|
||||||
String SM2SignC(int flag, String privateKey, byte[] publicKey, byte[] orgData);
|
byte[] 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 pUserID, String privateKey, byte[] publicKey, byte[] orgData);
|
||||||
/**
|
/**
|
||||||
* SM2 私钥签名
|
* SM2 私钥签名
|
||||||
* @param pUserID 使用者的 ID,最大长度为 16 位数字,右对齐。
|
* @param pUserID 使用者的 ID,最大长度为 16 位数字,右对齐。
|
||||||
@ -140,7 +140,7 @@ interface SydAttachedSVApi {
|
|||||||
int nOrgDataType,
|
int nOrgDataType,
|
||||||
byte[] publicKey,
|
byte[] publicKey,
|
||||||
byte[] orgData,
|
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 nOrgDataType 签名数据类型,SydApi.DATA_ORIGIN(1) 原始数据 SydApi.DATA_HASH(0) : hash 后的类型
|
||||||
* @param publicKey 公钥串,DER编码,HEX格式
|
* @param publicKey 公钥串,DER编码,HEX格式
|
||||||
* @param orgData 待签名的原始数据,“签名数据类型”为 0 时:HASH 值。“签名数据类型”为 1 时:要签名的信息
|
* @param orgData 待签名的原始数据,“签名数据类型”为 0 时:HASH 值。“签名数据类型”为 1 时:要签名的信息
|
||||||
* @param base64Sign 签名数据 (DER 编码 + Base64 编码)
|
* @param sign S+R
|
||||||
* @return 验签是否通过
|
* @return 验签是否通过
|
||||||
*/
|
*/
|
||||||
public boolean SM2Verify(
|
public boolean SM2Verify(
|
||||||
int nOrgDataType,
|
int nOrgDataType,
|
||||||
byte[] publicKey,
|
byte[] publicKey,
|
||||||
byte[] orgData,
|
byte[] orgData,
|
||||||
String base64Sign
|
byte[] sign
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -3347,6 +3347,13 @@ public class SydApi4j implements SydApi {
|
|||||||
// 测试通过
|
// 测试通过
|
||||||
public String SM2GetPrivateKeyC(String privateKeyTag) {
|
public String SM2GetPrivateKeyC(String privateKeyTag) {
|
||||||
|
|
||||||
|
if ( privateKeyTag.length() < 16 ) {
|
||||||
|
privateKeyTag = "0000000000000000" + privateKeyTag;
|
||||||
|
privateKeyTag = privateKeyTag.substring( privateKeyTag.length() -16 );
|
||||||
|
privateKeyTag += "00000000001";
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
ProtoQP proto = new ProtoQP();
|
ProtoQP proto = new ProtoQP();
|
||||||
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>();
|
||||||
@ -3591,12 +3598,12 @@ public class SydApi4j implements SydApi {
|
|||||||
* @param orgData 要签名的信息
|
* @param orgData 要签名的信息
|
||||||
* @return 签名结果
|
* @return 签名结果
|
||||||
*/
|
*/
|
||||||
public String SM2SignC(int flag, String privateKey, byte[] publicKey, byte[] orgData) {
|
public byte[] SM2SignC(int flag, String privateKey, byte[] publicKey, byte[] orgData) {
|
||||||
return SM2SignC( flag, "1234567812345678", privateKey, publicKey, orgData);
|
return SM2SignC( flag, "1234567812345678", privateKey, publicKey, orgData);
|
||||||
}
|
}
|
||||||
// 测试通过
|
// 测试通过
|
||||||
@Override
|
@Override
|
||||||
public String SM2SignC(int flag, String uid, String privateKey, byte[] publicKey, byte[] orgData) {
|
public byte[] SM2SignC(int flag, String uid, String privateKey, byte[] publicKey, byte[] orgData) {
|
||||||
|
|
||||||
Proto74 proto = new Proto74();
|
Proto74 proto = new Proto74();
|
||||||
|
|
||||||
@ -3637,7 +3644,7 @@ public class SydApi4j implements SydApi {
|
|||||||
byte[] s = new byte[a];
|
byte[] s = new byte[a];
|
||||||
bb.get(s, 0, a);
|
bb.get(s, 0, a);
|
||||||
|
|
||||||
return SYMUtil.derSign2Base64Sign(s);
|
return Util.decodeBase64( SYMUtil.derSign2Base64Sign(s) );
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -3813,10 +3820,10 @@ public class SydApi4j implements SydApi {
|
|||||||
int nOrgDataType,
|
int nOrgDataType,
|
||||||
byte[] publicKey,
|
byte[] publicKey,
|
||||||
byte[] orgData,
|
byte[] orgData,
|
||||||
String base64Sign
|
byte[] sign
|
||||||
){
|
){
|
||||||
String certNo = "1234567812345678";
|
String certNo = "1234567812345678";
|
||||||
return SM2Verify(certNo, nOrgDataType, publicKey, orgData, base64Sign);
|
return SM2Verify(certNo, nOrgDataType, publicKey, orgData, sign);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -3915,7 +3922,7 @@ public class SydApi4j implements SydApi {
|
|||||||
|
|
||||||
// 测试通过
|
// 测试通过
|
||||||
@Override
|
@Override
|
||||||
public boolean SM2Verify(String certNo, int nOrgDataType, byte[] publicKey, byte[] orgData, String base64Sign) {
|
public boolean SM2Verify(String certNo, int nOrgDataType, byte[] publicKey, byte[] orgData, byte[] sign) {
|
||||||
|
|
||||||
if (certNo.length() > 32) {
|
if (certNo.length() > 32) {
|
||||||
certNo = certNo.substring(0, 32);
|
certNo = certNo.substring(0, 32);
|
||||||
@ -3923,7 +3930,7 @@ public class SydApi4j implements SydApi {
|
|||||||
|
|
||||||
Proto75 proto = new Proto75(); //pset.getProtocolReqRender("75");
|
Proto75 proto = new Proto75(); //pset.getProtocolReqRender("75");
|
||||||
|
|
||||||
byte[] sign = SYMUtil.base64Sign2DerSign(base64Sign);
|
sign = SYMUtil.base64Sign2DerSign( Util.encodeBase64(sign) );
|
||||||
|
|
||||||
// 填充数据
|
// 填充数据
|
||||||
HashMap<String, Object> packet = new HashMap<String, Object>();
|
HashMap<String, Object> packet = new HashMap<String, Object>();
|
||||||
|
|||||||
75
src/test/java/com/sunyard/sydapi/loadrunner/raw/Actions.java
Normal file
75
src/test/java/com/sunyard/sydapi/loadrunner/raw/Actions.java
Normal file
@ -0,0 +1,75 @@
|
|||||||
|
package com.sunyard.sydapi.loadrunner.raw;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* LoadRunner Java script. (Build: _build_number_)
|
||||||
|
*
|
||||||
|
* Script Description:
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
import lrapi.lr;
|
||||||
|
import racal.sunyard.main.SydApi4j;
|
||||||
|
import racal.sunyard.main.SydApiBuilder;
|
||||||
|
import com.sunyard.proto.Util;
|
||||||
|
import com.sunyard.SydApi;
|
||||||
|
|
||||||
|
public class Actions
|
||||||
|
{
|
||||||
|
|
||||||
|
private static final String inHexData = "67c6697351ff4aec29cdbaabf2fbe346";
|
||||||
|
|
||||||
|
private static String pk ;
|
||||||
|
private static String sk ;
|
||||||
|
private SydApi api;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
public int init() throws Throwable {
|
||||||
|
SydApiBuilder builder = new SydApiBuilder().setIp("192.168.1.123");
|
||||||
|
api = builder.build();
|
||||||
|
|
||||||
|
this.pk = api.SM2GetPublicKeyC("123", 0 );
|
||||||
|
this.sk = api.SM2GetPrivateKeyC("123");
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}//end of init
|
||||||
|
|
||||||
|
|
||||||
|
public int action() throws Throwable {
|
||||||
|
lr.start_transaction("auto");//设置事务开始点
|
||||||
|
|
||||||
|
try {
|
||||||
|
|
||||||
|
System.out.println("begin SYD_Sign_P1");
|
||||||
|
byte[] sign = this.api.SM2SignC( 0 , sk, Util.hexString2Bytes(pk), Util.hexString2Bytes(inHexData) );
|
||||||
|
System.out.println("sign=" + Util.bytes2HexString( sign ));
|
||||||
|
|
||||||
|
System.out.println("begin SYD_Verify_P1");
|
||||||
|
boolean pass = api.SM2Verify(1, Util.hexString2Bytes(pk), Util.hexString2Bytes(inHexData), sign );
|
||||||
|
System.out.println("验签结果 " + pass);
|
||||||
|
System.out.println("end SYD_Verify_P1");
|
||||||
|
|
||||||
|
} finally {
|
||||||
|
lr.end_transaction("auto", lr.AUTO);//设置事务结束点
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}//end of action
|
||||||
|
|
||||||
|
|
||||||
|
public int end() throws Throwable {
|
||||||
|
return 0;
|
||||||
|
}//end of end
|
||||||
|
|
||||||
|
|
||||||
|
public static void main(String[] args) throws Throwable {
|
||||||
|
|
||||||
|
Actions actions = new Actions();
|
||||||
|
actions.init();
|
||||||
|
actions.action();
|
||||||
|
actions.end();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -0,0 +1,76 @@
|
|||||||
|
package com.sunyard.sydapi.loadrunner.raw_uid;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* LoadRunner Java script. (Build: _build_number_)
|
||||||
|
*
|
||||||
|
* Script Description:
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
import lrapi.lr;
|
||||||
|
import racal.sunyard.main.SydApi4j;
|
||||||
|
import racal.sunyard.main.SydApiBuilder;
|
||||||
|
import com.sunyard.proto.Util;
|
||||||
|
import com.sunyard.SydApi;
|
||||||
|
|
||||||
|
public class Actions
|
||||||
|
{
|
||||||
|
|
||||||
|
private static final String inHexData = "67c6697351ff4aec29cdbaabf2fbe346";
|
||||||
|
private static final String uid = "8765432187654321";
|
||||||
|
|
||||||
|
private static String pk ;
|
||||||
|
private static String sk ;
|
||||||
|
private SydApi api;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
public int init() throws Throwable {
|
||||||
|
SydApiBuilder builder = new SydApiBuilder().setIp("192.168.1.123");
|
||||||
|
api = builder.build();
|
||||||
|
|
||||||
|
this.pk = api.SM2GetPublicKeyC("123", 0 );
|
||||||
|
this.sk = api.SM2GetPrivateKeyC("123");
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}//end of init
|
||||||
|
|
||||||
|
|
||||||
|
public int action() throws Throwable {
|
||||||
|
lr.start_transaction("auto");//设置事务开始点
|
||||||
|
|
||||||
|
try {
|
||||||
|
|
||||||
|
System.out.println("begin SYD_Sign_P1");
|
||||||
|
byte[] sign = this.api.SM2SignC( 0, uid , sk, Util.hexString2Bytes(pk), Util.hexString2Bytes(inHexData) );
|
||||||
|
System.out.println("sign=" + Util.bytes2HexString( sign ));
|
||||||
|
|
||||||
|
System.out.println("begin SYD_Verify_P1");
|
||||||
|
boolean pass = api.SM2Verify( uid, 1, Util.hexString2Bytes(pk), Util.hexString2Bytes(inHexData), sign );
|
||||||
|
System.out.println("验签结果 " + pass);
|
||||||
|
System.out.println("end SYD_Verify_P1");
|
||||||
|
|
||||||
|
} finally {
|
||||||
|
lr.end_transaction("auto", lr.AUTO);//设置事务结束点
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}//end of action
|
||||||
|
|
||||||
|
|
||||||
|
public int end() throws Throwable {
|
||||||
|
return 0;
|
||||||
|
}//end of end
|
||||||
|
|
||||||
|
|
||||||
|
public static void main(String[] args) throws Throwable {
|
||||||
|
|
||||||
|
Actions actions = new Actions();
|
||||||
|
actions.init();
|
||||||
|
actions.action();
|
||||||
|
actions.end();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -1,203 +0,0 @@
|
|||||||
package com.sunyard.sydapi.test;
|
|
||||||
|
|
||||||
import com.sunyard.RetWrap;
|
|
||||||
import com.sunyard.SydApi;
|
|
||||||
import com.sunyard.proto.Util;
|
|
||||||
import org.junit.After;
|
|
||||||
import org.junit.Before;
|
|
||||||
import org.junit.Test;
|
|
||||||
import racal.sunyard.main.SydApi4j;
|
|
||||||
|
|
||||||
import java.io.UnsupportedEncodingException;
|
|
||||||
|
|
||||||
import static com.sunyard.sydapi.util.PrintUtil.printByteArray;
|
|
||||||
import static com.sunyard.sydapi.util.PrintUtil.printRetWrap;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 农行北分海淀支行-军队资金集中收付系统
|
|
||||||
*/
|
|
||||||
public class ABCNorthBranch {
|
|
||||||
|
|
||||||
SydApi4j api;
|
|
||||||
|
|
||||||
// SM2密钥索引
|
|
||||||
String SM2PrivateKeyTag = "111111111111115100000000001";
|
|
||||||
// SM2公钥
|
|
||||||
String SM2PublicKey = null;
|
|
||||||
// SM2私钥
|
|
||||||
String SM2PrivateKey = null;
|
|
||||||
|
|
||||||
// SM4密钥索引
|
|
||||||
String SM4PrivateKeyTag = "000000000000000100011111111";
|
|
||||||
// SM4密钥
|
|
||||||
String SM4Key = null;
|
|
||||||
|
|
||||||
|
|
||||||
@Before
|
|
||||||
public void before() {
|
|
||||||
System.setProperty("com.sunyard.sydapi4j.debug", "true");
|
|
||||||
api = (SydApi4j) new SydApi4j().connect("61.164.40.82", 8889, null, 5000);
|
|
||||||
|
|
||||||
SM2PublicKey = api.SM2GetPublicKeyC(SM2PrivateKeyTag);
|
|
||||||
SM2PrivateKey = api.SM2GetPrivateKeyC(SM2PrivateKeyTag);
|
|
||||||
|
|
||||||
|
|
||||||
SM4Key = new String((byte[]) api.readKey(SM4PrivateKeyTag).get("key"));
|
|
||||||
|
|
||||||
System.out.println("=========================================密钥获取完成=========================================");
|
|
||||||
}
|
|
||||||
|
|
||||||
@After
|
|
||||||
public void after() {
|
|
||||||
try {
|
|
||||||
this.api.disconnect();
|
|
||||||
} catch (Exception e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// A4
|
|
||||||
@Test
|
|
||||||
public void testComposeKey() {
|
|
||||||
String[] strs = {"583034303438393445374238444531323942344646344546393838394535364132", "583934443335443836454631463332313344353543343738323246383744333835"};
|
|
||||||
RetWrap rw = api.composeKey("000", strs);
|
|
||||||
|
|
||||||
printRetWrap(rw);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// 测试通过
|
|
||||||
// 74
|
|
||||||
@Test
|
|
||||||
public void testSM2SignC2() {
|
|
||||||
String thisOrgData = "FFFFFFFFFFFFFFFF";
|
|
||||||
|
|
||||||
String s = api.SM2SignC(1, SM2PrivateKeyTag, Util.hexString2Bytes(SM2PublicKey), thisOrgData.getBytes());
|
|
||||||
System.out.println(s);
|
|
||||||
}
|
|
||||||
|
|
||||||
// 测试通过
|
|
||||||
// 74
|
|
||||||
@Test
|
|
||||||
public void testSM2SignC3() {
|
|
||||||
String thisOrgData = "FFFFFFFFFFFFFFFF";
|
|
||||||
|
|
||||||
String s = api.SM2SignC(0, SM2PrivateKey, Util.hexString2Bytes(SM2PublicKey), thisOrgData.getBytes());
|
|
||||||
System.out.println(s);
|
|
||||||
}
|
|
||||||
|
|
||||||
// 75
|
|
||||||
@Test
|
|
||||||
public void testSM2SignAndVerify() {
|
|
||||||
String orgData = "11111111111111";
|
|
||||||
|
|
||||||
// 这里,不管是签名还是验签,都需要在外部做一次hash。
|
|
||||||
byte[] hash = api.SM3Hash(SM2PublicKey, orgData.getBytes());
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 用私钥签名(外部私钥)
|
|
||||||
* @param nOrgDataType 签名数据类型,0 : hash 1 : 原数据
|
|
||||||
* @param privateKey LMK34-35 下加密的私钥
|
|
||||||
* @param orgData “签名数据类型”为 0 时:HASH 值。“签名数据类型”为 1 时:要签名的信息
|
|
||||||
* @return 签名的 base64 编码
|
|
||||||
*/
|
|
||||||
String s = api.SM2Sign(SydApi.DATA_HASH, Util.hexString2Bytes(SM2PrivateKey), hash);
|
|
||||||
|
|
||||||
// 这里的签名结果已经符合条件了,不需要做转换
|
|
||||||
System.out.println("签名结果: " + s);
|
|
||||||
System.out.println("decBase64:" + Util.bytes2HexString(Util.decodeBase64(s)));
|
|
||||||
/**
|
|
||||||
* 用指定的公钥对指定的原始数据进行数字签名验证(PKCS#1)
|
|
||||||
* @param nOrgDataType 签名数据类型,SydApi.DATA_ORIGIN(1) 原始数据 SydApi.DATA_HASH(0) : hash 后的类型
|
|
||||||
* @param publicKey 公钥串,DER编码,HEX格式
|
|
||||||
* @param orgData 待签名的原始数据,“签名数据类型”为 0 时:HASH 值。“签名数据类型”为 1 时:要签名的信息
|
|
||||||
* @param base64Sign 签名数据 (DER 编码 + Base64 编码)
|
|
||||||
* @return 验签是否通过
|
|
||||||
*/
|
|
||||||
boolean b = api.SM2Verify(SydApi.DATA_HASH, Util.hexString2Bytes(SM2PublicKey), hash, s);
|
|
||||||
System.out.println("验签结果: " + b);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// 测试通过
|
|
||||||
// 75
|
|
||||||
@Test
|
|
||||||
public void testSM2Verify3() {
|
|
||||||
|
|
||||||
String thisOrgData = "FFFFFFFFFFFFFFFF";
|
|
||||||
|
|
||||||
String s = api.SM2SignC(1, SM2PrivateKeyTag, Util.hexString2Bytes(SM2PublicKey), thisOrgData.getBytes());
|
|
||||||
|
|
||||||
System.out.println(s);
|
|
||||||
boolean b = api.SM2Verify(Util.hexString2Bytes(SM2PublicKey), thisOrgData.getBytes(), s);
|
|
||||||
System.out.println(b);
|
|
||||||
}
|
|
||||||
|
|
||||||
// 测试通过
|
|
||||||
// E0
|
|
||||||
@Test
|
|
||||||
public void testSM4EncryptDataCBC() {
|
|
||||||
String msg = "1111111111111111111111";
|
|
||||||
byte[] bytes = api.SM4EncryptDataCBC(0, SM4Key, 0, 0, msg.getBytes());
|
|
||||||
printByteArray(bytes);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
// 测试通过
|
|
||||||
// E0
|
|
||||||
@Test
|
|
||||||
public void testSM4DecryptDataCBC() {
|
|
||||||
String msg = "11111111111";
|
|
||||||
byte[] bytes = api.SM4EncryptDataCBC(0, SM4Key, 0, 0, msg.getBytes());
|
|
||||||
|
|
||||||
byte[] bytes1 = api.SM4DecryptDataCBC(0, SM4Key, 0, 0, bytes);
|
|
||||||
|
|
||||||
printByteArray(bytes1, false);
|
|
||||||
}
|
|
||||||
|
|
||||||
// 测试通过
|
|
||||||
// E0
|
|
||||||
@Test
|
|
||||||
public void testSM4EncryptFileDataCBC() {
|
|
||||||
|
|
||||||
String inFilePath = "C:\\Users\\edgar\\Desktop\\fsdownload\\test\\in1.txt";
|
|
||||||
String outFilePath = "C:\\Users\\edgar\\Desktop\\fsdownload\\test\\in2.txt";
|
|
||||||
boolean b = api.SM4EncryptFileDataCBC(0, SM4Key, 0, 0, inFilePath, outFilePath);
|
|
||||||
System.out.println(b);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// 测试通过
|
|
||||||
// E0
|
|
||||||
@Test
|
|
||||||
public void testSM4DecryptFileDataCBC() throws UnsupportedEncodingException {
|
|
||||||
|
|
||||||
String outFilePath = "C:\\Users\\edgar\\Desktop\\fsdownload\\test\\in2.txt";
|
|
||||||
String outFilePath2 = "C:\\Users\\edgar\\Desktop\\fsdownload\\test\\out1.txt";
|
|
||||||
boolean b = api.SM4DecryptFileDataCBC(0, SM4Key, 0, 0, outFilePath, outFilePath2);
|
|
||||||
System.out.println(b);
|
|
||||||
}
|
|
||||||
|
|
||||||
// LF
|
|
||||||
@Test
|
|
||||||
public void testReadKey() {
|
|
||||||
RetWrap retWrap = api.readKey(SM4PrivateKeyTag);
|
|
||||||
printRetWrap(retWrap);
|
|
||||||
}
|
|
||||||
|
|
||||||
// QQ
|
|
||||||
@Test
|
|
||||||
public void testSM2GetPublicKeyC3() {
|
|
||||||
|
|
||||||
String s = api.SM2GetPublicKeyC(SM2PrivateKeyTag);
|
|
||||||
System.out.println(s);
|
|
||||||
}
|
|
||||||
|
|
||||||
// QP
|
|
||||||
@Test
|
|
||||||
public void testSM2GetPrivateKeyC() {
|
|
||||||
String s = api.SM2GetPrivateKeyC(SM2PrivateKeyTag);
|
|
||||||
System.out.println(s);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
File diff suppressed because it is too large
Load Diff
121
src/test/java/com/sunyard/sydapi/test/TestICBC.java
Normal file
121
src/test/java/com/sunyard/sydapi/test/TestICBC.java
Normal file
@ -0,0 +1,121 @@
|
|||||||
|
package com.sunyard.sydapi.test;
|
||||||
|
|
||||||
|
|
||||||
|
import com.sunyard.RetWrap;
|
||||||
|
import com.sunyard.SydApi;
|
||||||
|
import com.sunyard.proto.Util;
|
||||||
|
import racal.sunyard.main.SydApi4j;
|
||||||
|
|
||||||
|
import java.io.UnsupportedEncodingException;
|
||||||
|
import java.util.Arrays;
|
||||||
|
|
||||||
|
public class TestICBC {
|
||||||
|
public static void main(String[] args) throws UnsupportedEncodingException {
|
||||||
|
|
||||||
|
|
||||||
|
SydApi4j.SYD_Set_Parameter_HA("unkown", "172.16.17.162", 8889 , 1000);
|
||||||
|
|
||||||
|
SydApi4j api = (SydApi4j) new SydApi4j();//.connect("wuyong.fullstack.club" , 8889, null,1000);
|
||||||
|
|
||||||
|
|
||||||
|
RetWrap r = api.SYD_SM2GenKeyPair();
|
||||||
|
System.out.println( r.get("publicKey") );
|
||||||
|
System.out.println( r.get("privateKey") );
|
||||||
|
|
||||||
|
// System.out.println("\n\n----- 获取公钥 () -----");
|
||||||
|
// String pk = api.SYD_SM2_Get_Id_PublicKey_HA("1234", 0);
|
||||||
|
// System.out.print("\r\n公钥 : ");
|
||||||
|
// System.out.println( pk );
|
||||||
|
//
|
||||||
|
//
|
||||||
|
//// pk = api.SYD_SM2_Get_Dn_PublicKey_HA("C=CN,O=Sunyard,OU=8001,CN=8001".getBytes("GBK"), 0);
|
||||||
|
//// System.out.print("\r\n公钥 : ");
|
||||||
|
//// System.out.println( pk );
|
||||||
|
//
|
||||||
|
//
|
||||||
|
// // 签名
|
||||||
|
String data="MainBody><MsgId><Id>101557000040870201809190000000001</Id><CreDtTm>2018-09-19T10:13:39</CreDtTm></MsgId><Qryr><MbrId>101557</MbrId><BrId>000040870</BrId></Qryr><Rspnr><MbrId>201597</MbrId><BrId>000039754</BrId></Rspnr><BizQryInf><QryDt>2018-09-19</QryDt><QryId>00000001</QryId><Cnts>123456,测试</Cnts></BizQryInf></MainBody>";
|
||||||
|
final String testPubKey = "0342000480C7E165DB8CF019509CE359C4FE06535275F5F63ADDC3955721FA4802BDC8701661554096BBC190916F39073C3763C8BEF6ABDF7A042C9F1D12B6BD6E5E2614";
|
||||||
|
// System.out.println("\n\n----- SM2 算法签名 (原始数据) -----");
|
||||||
|
// String sign = api.SYD_SM2_Sign_HA(
|
||||||
|
// "1234",
|
||||||
|
// SydApi.DATA_ORIGIN,
|
||||||
|
// Util.hexString2Bytes(testPubKey),
|
||||||
|
// data.getBytes()
|
||||||
|
// );
|
||||||
|
// System.out.print("\n\n----- SM2 算法签名 结果: ");
|
||||||
|
// System.out.println( sign );
|
||||||
|
//
|
||||||
|
//
|
||||||
|
//
|
||||||
|
//
|
||||||
|
//
|
||||||
|
// System.out.println("\n\n----- SM2 算法验签 (原始数据) -----");
|
||||||
|
// boolean SM2VerifyRet = api.SYD_SM2_Verify_HA(
|
||||||
|
// SydApi.DATA_ORIGIN,
|
||||||
|
// Util.hexString2Bytes(testPubKey), data.getBytes() , sign);
|
||||||
|
// if (SM2VerifyRet){
|
||||||
|
// System.out.println("验签通过");
|
||||||
|
// }else{
|
||||||
|
// System.err.println("验签失败");
|
||||||
|
// throw new RuntimeException("验签失败");
|
||||||
|
// }
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// // 签名验签 2
|
||||||
|
// System.out.println("\n\n----- 签名验签 2 -----");
|
||||||
|
// String sign2 = api.SYD_SM2_DetachedSign_HA( data.getBytes() , "C=CN,O=Sunyard,OU=8001,CN=8001");
|
||||||
|
// System.out.println( sign2 );
|
||||||
|
|
||||||
|
|
||||||
|
// String sign2 = "MIICpQYKKoEcz1UGAQQCAqCCApUwggKRAgEBMQ4wDAYIKoEcz1UBgxEFADAMBgoqgRzPVQYBBAIBoIIByTCCAcUwggFooAMCAQICCDyTAAAAAAAlMAwGCCqBHM9VAYN1BQAwJjELMAkGA1UEBhMCQ04xFzAVBgNVBAMMDlN1bnlhcmRTTTJSb290MB4XDTE3MDUxNzAyNTI0NFoXDTIyMDcyNTAyNTI0NFowPTELMAkGA1UEBhMCQ04xEDAOBgNVBAoMB1N1bnlhcmQxDTALBgNVBAsMBDgwMDExDTALBgNVBAMMBDgwMDEwWTATBgcqhkjOPQIBBggqgRzPVQGCLQNCAAQ+2joQe3zDXMAFx/vwu05rQ6B+4U42BgPSLsoqYAstD6AwVdQA0SQDAPVGSLhJ0T9QszD/FDUbVkWxNoaCCmW7o2cwZTAOBgNVHQ8BAf8EBAMCAMAwEwYDVR0lBAwwCgYIKwYBBQUHAwEwHwYDVR0jBBgwFoAU93/arv8hxtk6eq2g+6z+AqVO1cEwHQYDVR0OBBYEFAMWZaY2AwaQTNiFLpsa0dyCzBZ6MAwGCCqBHM9VAYN1BQADSQAwRgIhAIl2ZHGfln5hedcousARzZ2yeUjUbxSFMmhMmr5t6Q6nAiEAvqYX/KpIcvnPyB/Yiil+oq6DFdVM6P3vDxBhU/8taXExgaAwgZ0CAQEwMjAmMQswCQYDVQQGEwJDTjEXMBUGA1UEAwwOU3VueWFyZFNNMlJvb3QCCDyTAAAAAAAlMAwGCCqBHM9VAYMRBQAwDQYJKoEcz1UBgi0BBQAERzBFAiATwLIYiylt7xHmBkH6EclrchClxzLlKWC5guxxzkr58gIhANSw+owu8cyypdJtHGrGqjSiB1BVzGva+irUHelx/GbC";
|
||||||
|
// sign2 = "MIID7gYKKoEcz1UGAQQCAqCCA94wggPaAgEBMQ4wDAYIKoEcz1UBgxEFADAMBgoqgRzPVQYBBAIBoIIC2jCCAtYwggJ6oAMCAQICBUACgAF0MAwGCCqBHM9VAYN1BQAwYTELMAkGA1UEBhMCQ04xMDAuBgNVBAoMJ0NoaW5hIEZpbmFuY2lhbCBDZXJ0aWZpY2F0aW9uIEF1dGhvcml0eTEgMB4GA1UEAwwXQ0ZDQSBBQ1MgVEVTVCBTTTIgT0NBMzEwHhcNMTcxMTE2MDY1NDQ1WhcNMjIxMTE2MDY1NDQ1WjCBgzELMAkGA1UEBhMCQ04xHDAaBgNVBAoME0NGQ0EgVEVTVCBTTTIgT0NBMzExDjAMBgNVBAsMBVNIQ1BFMRkwFwYDVQQLDBBPcmdhbml6YXRpb25hbC0xMSswKQYDVQQDDCIwNTFA5LiK5rW356Wo5o2u5Lqk5piT5omAQEFBQUFBQUA4MFkwEwYHKoZIzj0CAQYIKoEcz1UBgi0DQgAEYPA9UQRL/ZaThEN0nc3SwkOHw4hPDXG9hZeKiBnNdhgPy1EtX4My2bpNFpYMmQ0nvkJUM4qpJrF7MSqEws6rLaOB+TCB9jA/BggrBgEFBQcBAQQzMDEwLwYIKwYBBQUHMAGGI2h0dHA6Ly9vY3NwdGVzdC5jZmNhLmNvbS5jbjo4MC9vY3NwMB8GA1UdIwQYMBaAFATHvPlZAWk+jDQ2IGIYPN68tbsMMAwGA1UdEwEB/wQCMAAwNgYDVR0fBC8wLTAroCmgJ4YlaHR0cDovLzIxMC43NC40Mi4zL09DQTMxL1NNMi9jcmwxLmNybDAOBgNVHQ8BAf8EBAMCBsAwHQYDVR0OBBYEFKJnS7XYRDWG9eqXtSzUZXK+De2/MB0GA1UdJQQWMBQGCCsGAQUFBwMCBggrBgEFBQcDBDAMBggqgRzPVQGDdQUAA0gAMEUCIGaSRoaUSpoH4lW3at1ABluiNwFDH21jHesHmy0F5gjqAiEA0sUykW9E36F3qQ91YDvasQg8EnOMp1idhgt6pq/NUAYxgdgwgdUCAQEwajBhMQswCQYDVQQGEwJDTjEwMC4GA1UECgwnQ2hpbmEgRmluYW5jaWFsIENlcnRpZmljYXRpb24gQXV0aG9yaXR5MSAwHgYDVQQDDBdDRkNBIEFDUyBURVNUIFNNMiBPQ0EzMQIFQAKAAXQwDAYIKoEcz1UBgxEFADANBgkqgRzPVQGCLQEFAARHMEUCIQDH3ePzq4nYJ8pAodJyqPKqCQuQwmOpyj/rWcDILzFj2gIgUW5c9W6jD7u91opMcDwaw4aNEvEtGX6ks5XDIMIkUjI=";
|
||||||
|
//
|
||||||
|
//
|
||||||
|
//
|
||||||
|
// boolean pass = api.SYD_SM2_DetachedVerify_HA( "<MainBody><MsgId><Id>000000000000000201809181000008627</Id><CreDtTm>2018-09-17T19:06:39</CreDtTm></MsgId><CertNtfctnInf><ChngTp>CC00</ChngTp></CertNtfctnInf></MainBody>".getBytes(), sign2 );
|
||||||
|
// System.out.println( pass );
|
||||||
|
//
|
||||||
|
// // 获取公钥
|
||||||
|
// X509 x = api.SYD_Get_X509_CertInfo_HA( "<MainBody><MsgId><Id>000000000000000201809181000008627</Id><CreDtTm>2018-09-17T19:06:39</CreDtTm></MsgId><CertNtfctnInf><ChngTp>CC00</ChngTp></CertNtfctnInf></MainBody>".getBytes(), sign2 );
|
||||||
|
// System.out.println( Util.bytes2HexString( x.getPubKey() ) );
|
||||||
|
|
||||||
|
byte[]ttt = new byte[40960];
|
||||||
|
Arrays.fill(ttt, (byte) 0x88);
|
||||||
|
String sign2 = api.SYD_SM2_Sign_HA(
|
||||||
|
"1234",
|
||||||
|
SydApi.DATA_HASH,
|
||||||
|
Util.hexString2Bytes("0342000480C7E165DB8CF019509CE359C4FE06535275F5F63ADDC3955721FA4802BDC8701661554096BBC190916F39073C3763C8BEF6ABDF7A042C9F1D12B6BD6E5E2614"),
|
||||||
|
ttt
|
||||||
|
);
|
||||||
|
System.out.print("\n\n----- SM2 算法签名 结果: ");
|
||||||
|
System.out.println( sign2 );
|
||||||
|
|
||||||
|
System.out.println( api.SYD_SM2_Verify_HA(
|
||||||
|
SydApi.DATA_HASH,
|
||||||
|
Util.hexString2Bytes("0342000480C7E165DB8CF019509CE359C4FE06535275F5F63ADDC3955721FA4802BDC8701661554096BBC190916F39073C3763C8BEF6ABDF7A042C9F1D12B6BD6E5E2614"),
|
||||||
|
ttt ,
|
||||||
|
sign2
|
||||||
|
) );
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
String sign3 = api.SYD_SM2_Sign_HA(
|
||||||
|
"1234",
|
||||||
|
SydApi.DATA_ORIGIN,
|
||||||
|
Util.hexString2Bytes("0342000480C7E165DB8CF019509CE359C4FE06535275F5F63ADDC3955721FA4802BDC8701661554096BBC190916F39073C3763C8BEF6ABDF7A042C9F1D12B6BD6E5E2614"),
|
||||||
|
"<MainBody><MsgId><Id>101557000040870201809190000000001</Id><CreDtTm>2018-09-19T10:13:39</CreDtTm></MsgId><Qryr><MbrId>101557</MbrId><BrId>000040870</BrId></Qryr><Rspnr><MbrId>201597</MbrId><BrId>000039754</BrId></Rspnr><BizQryInf><QryDt>2018-09-19</QryDt><QryId>00000001</QryId><Cnts>123456,测试</Cnts></BizQryInf></MainBody>".getBytes()
|
||||||
|
);
|
||||||
|
System.out.print("\n\n----- SM2 算法签名 结果: ");
|
||||||
|
System.out.println( sign3 );
|
||||||
|
|
||||||
|
System.out.println( api.SYD_SM2_Verify_HA(
|
||||||
|
SydApi.DATA_ORIGIN,
|
||||||
|
Util.hexString2Bytes("0342000480C7E165DB8CF019509CE359C4FE06535275F5F63ADDC3955721FA4802BDC8701661554096BBC190916F39073C3763C8BEF6ABDF7A042C9F1D12B6BD6E5E2614"),
|
||||||
|
"<MainBody><MsgId><Id>101557000040870201809190000000001</Id><CreDtTm>2018-09-19T10:13:39</CreDtTm></MsgId><Qryr><MbrId>101557</MbrId><BrId>000040870</BrId></Qryr><Rspnr><MbrId>201597</MbrId><BrId>000039754</BrId></Rspnr><BizQryInf><QryDt>2018-09-19</QryDt><QryId>00000001</QryId><Cnts>123456,测试</Cnts></BizQryInf></MainBody>".getBytes() ,
|
||||||
|
sign3
|
||||||
|
) );
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -1,104 +0,0 @@
|
|||||||
package com.sunyard.sydapi.test;
|
|
||||||
|
|
||||||
|
|
||||||
import com.sunyard.SydApi;
|
|
||||||
import com.sunyard.proto.Util;
|
|
||||||
import racal.sunyard.main.SydApi4j;
|
|
||||||
import racal.sunyard.main.SydApiBuilder;
|
|
||||||
|
|
||||||
import static com.sunyard.SydApi.*;
|
|
||||||
|
|
||||||
|
|
||||||
public class TestSV {
|
|
||||||
|
|
||||||
private static final String inHexData = "67c6697351ff4aec29cdbaabf2fbe346";
|
|
||||||
private static final String dn = "C=CN,ST=浙江,L=杭州,O=信雅达测试123,OU=安全应用1,OU=安全应用2,CN=@信雅达安全测试";
|
|
||||||
|
|
||||||
|
|
||||||
public static void main(String[] args) {
|
|
||||||
System.setProperty("com.sunyard.sydapi4j.debug", "true");
|
|
||||||
// 连接加密机
|
|
||||||
SydApi4j api = (SydApi4j) new SydApi4j().connect("172.16.18.59", 8889, null, 1000);
|
|
||||||
|
|
||||||
SydApiBuilder builder = new SydApiBuilder().setIp("192.168.5.88");
|
|
||||||
builder.build();
|
|
||||||
|
|
||||||
try {
|
|
||||||
|
|
||||||
// case1(api);
|
|
||||||
case4(api);
|
|
||||||
case5(api);
|
|
||||||
|
|
||||||
} catch (Exception e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
} finally {
|
|
||||||
api.disconnect();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void case1(SydApi api) {
|
|
||||||
String sign = api.attachedSign( Util.hexString2Bytes( inHexData ), dn );
|
|
||||||
System.out.println("签名结果 " + sign );
|
|
||||||
|
|
||||||
|
|
||||||
boolean pass = api.attachedVerify(sign);
|
|
||||||
System.out.println("验签结果 " + pass);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public static void case2(SydApi api) {
|
|
||||||
System.out.println("begin SYD_Sign_Detach");
|
|
||||||
String sign = api.detachedSign( DATA_ORIGIN, Util.hexString2Bytes( inHexData ), dn );
|
|
||||||
System.out.println("签名结果 " + sign );
|
|
||||||
System.out.println("begin SYD_Sign_Detach");
|
|
||||||
|
|
||||||
System.out.println("begin SYD_Verify_Detach");
|
|
||||||
boolean pass = api.detachedVerify(DATA_ORIGIN, Util.hexString2Bytes( inHexData ), sign);
|
|
||||||
System.out.println("验签结果 " + pass);
|
|
||||||
System.out.println("end SYD_Verify_Detach");
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public static void case3(SydApi api) {
|
|
||||||
System.out.println("begin SYD_NakedSign");
|
|
||||||
byte[] sign = api.SYD_NakedSign( Util.hexString2Bytes(inHexData) , dn);
|
|
||||||
System.out.println("签名结果 " + Util.bytes2HexString(sign) );
|
|
||||||
System.out.println("end SYD_NakedSign");
|
|
||||||
|
|
||||||
System.out.println("begin SYD_NakedVerify");
|
|
||||||
boolean pass = api.SYD_NakedVerify( Util.hexString2Bytes(inHexData), sign, dn);
|
|
||||||
System.out.println("验签结果 " + pass);
|
|
||||||
System.out.println("end SYD_NakedVerify");
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public static void case4(SydApi api) {
|
|
||||||
// 不传 ID
|
|
||||||
String pk = api.SM2GetPublicKeyC("65667", 0 );
|
|
||||||
String sk = api.SM2GetPrivateKeyC("000000000006566700000000001");
|
|
||||||
|
|
||||||
String sign = api.SM2SignC( 0, sk, Util.hexString2Bytes(pk), Util.hexString2Bytes(inHexData) );
|
|
||||||
System.out.println("签名结果 " + sign );
|
|
||||||
|
|
||||||
boolean pass = api.SM2Verify(Util.hexString2Bytes(pk), Util.hexString2Bytes(inHexData), sign );
|
|
||||||
System.out.println("验签结果 " + pass);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public static void case5(SydApi api) {
|
|
||||||
// 传 ID
|
|
||||||
String uid = "8765432187654321";
|
|
||||||
String pk = api.SM2GetPublicKeyC("65667", 0 );
|
|
||||||
String sk = api.SM2GetPrivateKeyC("000000000006566700000000001");
|
|
||||||
|
|
||||||
System.out.println("begin SYD_Sign_P1");
|
|
||||||
String sign = api.SM2SignC( 0, uid, sk, Util.hexString2Bytes(pk), Util.hexString2Bytes(inHexData) );
|
|
||||||
System.out.println("签名结果 " + Util.bytes2HexString( Util.decodeBase64( sign ) ) );
|
|
||||||
System.out.println("end SYD_Verify_P1");
|
|
||||||
|
|
||||||
System.out.println("begin SYD_Sign_P1");
|
|
||||||
boolean pass = api.SM2Verify(uid, 1, Util.hexString2Bytes(pk), Util.hexString2Bytes(inHexData), sign );
|
|
||||||
System.out.println("验签结果 " + pass);
|
|
||||||
System.out.println("end SYD_Verify_P1");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,457 +0,0 @@
|
|||||||
package com.sunyard.sydapi.test;
|
|
||||||
|
|
||||||
import com.sunyard.RetWrap;
|
|
||||||
import com.sunyard.SydApi;
|
|
||||||
import com.sunyard.cert.X509;
|
|
||||||
import com.sunyard.proto.Util;
|
|
||||||
import org.junit.After;
|
|
||||||
import org.junit.Before;
|
|
||||||
import org.junit.Test;
|
|
||||||
import racal.sunyard.main.SydApi4j;
|
|
||||||
|
|
||||||
import java.io.BufferedInputStream;
|
|
||||||
import java.io.FileInputStream;
|
|
||||||
import java.io.IOException;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 新疆联通政务云
|
|
||||||
*/
|
|
||||||
public class TestXJ {
|
|
||||||
|
|
||||||
SydApi4j api;
|
|
||||||
|
|
||||||
@Before
|
|
||||||
public void before() {
|
|
||||||
// 通过设置debug的属性开启debug,如果不设置则默认不打开
|
|
||||||
System.setProperty("com.sunyard.sydapi4j.debug", "true");
|
|
||||||
api = (SydApi4j) new SydApi4j().connect("192.168.0.100", 8889, null, 1000);
|
|
||||||
}
|
|
||||||
|
|
||||||
@After
|
|
||||||
public void after() {
|
|
||||||
try {
|
|
||||||
this.api.disconnect();
|
|
||||||
} catch (Exception e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// 测试通过
|
|
||||||
// 8003
|
|
||||||
@Test
|
|
||||||
public void testSYD_NakedSign() {
|
|
||||||
String dn = "C=CN,O=Sunyard,OU=8001,CN=8001";
|
|
||||||
byte[] bytes = api.SYD_NakedSign("111".getBytes(), dn);
|
|
||||||
System.out.println(Util.bytes2HexString(bytes));
|
|
||||||
}
|
|
||||||
|
|
||||||
// 测试通过
|
|
||||||
// 8004
|
|
||||||
@Test
|
|
||||||
public void testSYD_NakedVerify() {
|
|
||||||
String dn = "C=CN,O=Sunyard,OU=8001,CN=8001";
|
|
||||||
String orgData = "111";
|
|
||||||
byte[] bytes = api.SYD_NakedSign(orgData.getBytes(), dn);
|
|
||||||
String sign = Util.bytes2HexString(bytes);
|
|
||||||
System.out.println(sign);
|
|
||||||
|
|
||||||
boolean b = api.SYD_NakedVerify(orgData.getBytes(), bytes, dn);
|
|
||||||
System.out.println(b);
|
|
||||||
}
|
|
||||||
|
|
||||||
// 测试通过
|
|
||||||
// 6C
|
|
||||||
@Test
|
|
||||||
public void testNetSign() {
|
|
||||||
String sn = "1004282451";
|
|
||||||
String s = api.netSign(sn, "111".getBytes());
|
|
||||||
System.out.println(s);
|
|
||||||
}
|
|
||||||
|
|
||||||
// 测试通过
|
|
||||||
// 6D
|
|
||||||
@Test
|
|
||||||
public void testNetVerify() {
|
|
||||||
String sn = "1004282451";
|
|
||||||
String data = "111";
|
|
||||||
String s = api.netSign(sn, data.getBytes());
|
|
||||||
|
|
||||||
boolean b = api.netVerify(sn, data.getBytes(), s);
|
|
||||||
System.out.println(b);
|
|
||||||
}
|
|
||||||
|
|
||||||
// 测试通过
|
|
||||||
// 80
|
|
||||||
@Test
|
|
||||||
public void testSM2SignCustomized() {
|
|
||||||
String sn = "1004282452";
|
|
||||||
String s = api.SM2SignCustomized(sn, "111".getBytes());
|
|
||||||
System.out.println(s);
|
|
||||||
}
|
|
||||||
|
|
||||||
// 测试通过
|
|
||||||
// 81
|
|
||||||
@Test
|
|
||||||
public void testSM2VerifyCustomized() {
|
|
||||||
String sn = "1004282451";
|
|
||||||
String data = "111";
|
|
||||||
String s = api.SM2SignCustomized(sn, data.getBytes());
|
|
||||||
|
|
||||||
boolean b = api.SM2VerifyCustomized(sn, data.getBytes(), s);
|
|
||||||
System.out.println(b);
|
|
||||||
}
|
|
||||||
|
|
||||||
// 测试通过
|
|
||||||
// 74
|
|
||||||
@Test
|
|
||||||
public void testSM2SignC() {
|
|
||||||
String userId = "1111111111111113";
|
|
||||||
String certNo = "1234567812345678";
|
|
||||||
String thisPublicKey = "03420004549B6A1A09A5D0D9432C6829D443F85ED8785340FC1AB14118BB7637830C808F7A888DF0C4F988EA6FF2EE6C76ECD00C4B7CEC92CC8EA365F8EA291041CAB231";
|
|
||||||
String thisOrgData = "FFFFFFFFFFFFFFFF";
|
|
||||||
|
|
||||||
String s = api.SM2SignC(userId, certNo, 1, Util.hexString2Bytes(thisPublicKey), thisOrgData.getBytes());
|
|
||||||
System.out.println(s);
|
|
||||||
}
|
|
||||||
|
|
||||||
// 测试通过
|
|
||||||
// 75
|
|
||||||
@Test
|
|
||||||
public void testSM2Verify() {
|
|
||||||
|
|
||||||
String userId = "1111111111111113";
|
|
||||||
String certNo = "1234567812345678";
|
|
||||||
String thisPublicKey = "03420004549B6A1A09A5D0D9432C6829D443F85ED8785340FC1AB14118BB7637830C808F7A888DF0C4F988EA6FF2EE6C76ECD00C4B7CEC92CC8EA365F8EA291041CAB231";
|
|
||||||
String thisOrgData = "FFFFFFFFFFFFFFFF";
|
|
||||||
|
|
||||||
String s = api.SM2SignC(userId, certNo, 1, Util.hexString2Bytes(thisPublicKey), thisOrgData.getBytes());
|
|
||||||
|
|
||||||
System.out.println(s);
|
|
||||||
boolean b = api.SM2Verify(certNo, 1, Util.hexString2Bytes(thisPublicKey), thisOrgData.getBytes(), s);
|
|
||||||
System.out.println(b);
|
|
||||||
}
|
|
||||||
|
|
||||||
// 测试通过
|
|
||||||
// 8005
|
|
||||||
@Test
|
|
||||||
public void testSYD_DetachedSign() {
|
|
||||||
|
|
||||||
String orgData = "3214312341243214";
|
|
||||||
String DN = "C=CN,O=Sunyard,OU=8001,CN=8001";
|
|
||||||
String s = api.SYD_DetachedSign(orgData.getBytes(), DN);
|
|
||||||
System.out.println(s);
|
|
||||||
}
|
|
||||||
|
|
||||||
// 测试通过
|
|
||||||
// 8006
|
|
||||||
@Test
|
|
||||||
public void testSYD_DetachedVerify() {
|
|
||||||
String orgData = "3214312341243214";
|
|
||||||
String DN = "C=CN,O=Sunyard,OU=8001,CN=8001";
|
|
||||||
String sign = api.SYD_DetachedSign(orgData.getBytes(), DN);
|
|
||||||
System.out.println("签名结果" + sign);
|
|
||||||
|
|
||||||
boolean b = api.SYD_DetachedVerify(orgData.getBytes(), sign);
|
|
||||||
System.out.println("验签结果:" + b);
|
|
||||||
}
|
|
||||||
|
|
||||||
// 测试通过
|
|
||||||
// 8005
|
|
||||||
@Test
|
|
||||||
public void testSm3AndDetachedSign() {
|
|
||||||
String publicKey = "0342000469DE3847DD6A66DA96DB8F2DCFA32E10E680FF2EF4A592079E7C3A44320BB15084E7CA9782A39B6E28F07C04FE00D68958A2605921E71712D56C1E4435A39FA5";
|
|
||||||
String orgData = "FFFFFFFFFFFFFFFF";
|
|
||||||
String testCertNo = "C=CN,O=Sunyard,OU=8001,CN=8001";
|
|
||||||
|
|
||||||
String sign = api.sm3AndDetachedSign(orgData.getBytes(), publicKey, testCertNo);
|
|
||||||
System.out.println("签名结果: " + sign);
|
|
||||||
|
|
||||||
boolean b = api.sm3AndDetachedVerify(orgData.getBytes(), publicKey, sign);
|
|
||||||
System.out.println("验签结果:" + b);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// 测试通过
|
|
||||||
// 8005
|
|
||||||
@Test
|
|
||||||
public void testDetachedSign() {
|
|
||||||
String publicKey = "0342000469DE3847DD6A66DA96DB8F2DCFA32E10E680FF2EF4A592079E7C3A44320BB15084E7CA9782A39B6E28F07C04FE00D68958A2605921E71712D56C1E4435A39FA5";
|
|
||||||
String orgData = "FFFFFFFFFFFFFFFF";
|
|
||||||
String testCertNo = "C=CN,O=Sunyard,OU=8001,CN=8001";
|
|
||||||
|
|
||||||
byte[] hash = api.SM3Hash(publicKey, orgData.getBytes());
|
|
||||||
|
|
||||||
String sign = api.detachedSign(
|
|
||||||
SydApi.DATA_HASH,
|
|
||||||
hash,
|
|
||||||
testCertNo
|
|
||||||
);
|
|
||||||
|
|
||||||
System.out.println("\t签名结果: " + sign);
|
|
||||||
|
|
||||||
boolean verify = api.detachedVerify(
|
|
||||||
SydApi.DATA_HASH,
|
|
||||||
hash,
|
|
||||||
sign
|
|
||||||
);
|
|
||||||
|
|
||||||
System.out.println("\t验签结果: " + verify);
|
|
||||||
}
|
|
||||||
|
|
||||||
// 测试通过
|
|
||||||
// 72
|
|
||||||
@Test
|
|
||||||
public void testSM2GenSessionKey() {
|
|
||||||
|
|
||||||
String pk="034200041CD47354867E12B9D138F098413C47D42EDEB2AD402EAB431C0C7AC2FE2D6DE9C67273C643C709F2A749188941B7FA7F9FF14F8E7D19316936DB4D4954FF3819";
|
|
||||||
|
|
||||||
RetWrap retWrap = api.SM2GenSessionKey(pk);
|
|
||||||
printRetWrap(retWrap);
|
|
||||||
}
|
|
||||||
|
|
||||||
// 测试通过
|
|
||||||
// 73
|
|
||||||
@Test
|
|
||||||
public void testSM2ConfirmSessionKeyC() {
|
|
||||||
|
|
||||||
String userId = "1111111111111147";
|
|
||||||
|
|
||||||
String pk="0342000422C4FC907E0BEC600C2070D675EFB65EAE3A628260FF5461DD5F8133CF7CF98530EF392D016B6487BA6148E9AC27BDD4E8D7404A310CB09335F50AEF00ADB068";
|
|
||||||
|
|
||||||
RetWrap retWrap = api.SM2GenSessionKey(pk);
|
|
||||||
printRetWrap(retWrap);
|
|
||||||
|
|
||||||
String cipherKey = (String) retWrap.get("CipherKey");
|
|
||||||
|
|
||||||
RetWrap retWrap1 = api.SM2ConfirmSessionKeyC(userId, cipherKey);
|
|
||||||
printRetWrap(retWrap1);
|
|
||||||
}
|
|
||||||
|
|
||||||
// 测试通过
|
|
||||||
// E0
|
|
||||||
@Test
|
|
||||||
public void testSYMEncryptData() {
|
|
||||||
String sessionKey = "XF356BCBA3204F6E6F356BCBA3204F6E6";
|
|
||||||
String pInData = "1111111111111111";
|
|
||||||
|
|
||||||
byte[] bytes = api.SYMEncryptData(3,sessionKey, pInData.getBytes());
|
|
||||||
byte[] bytes1 = api.SYMDecryptData(3, sessionKey, bytes);
|
|
||||||
System.out.println(new String(bytes1));
|
|
||||||
}
|
|
||||||
|
|
||||||
// 测试通过
|
|
||||||
// E0
|
|
||||||
@Test
|
|
||||||
public void testEncDecData() {
|
|
||||||
|
|
||||||
String msg = "1111111111111111111111";
|
|
||||||
|
|
||||||
String key = "X3C9003C47A13379011733681ABB4A4D0";
|
|
||||||
|
|
||||||
byte[] bytes = api.SYMEncryptDataCBC(1, key, msg.getBytes());
|
|
||||||
|
|
||||||
System.out.println("输出为: " + Util.bytes2HexString(bytes));
|
|
||||||
|
|
||||||
byte[] bytes1 = api.SYMDecryptDataCBC(1, key, bytes);
|
|
||||||
System.out.println("明文:" + new String(bytes1));
|
|
||||||
}
|
|
||||||
|
|
||||||
// 测试通过
|
|
||||||
// 6B
|
|
||||||
@Test
|
|
||||||
public void testDecryptDE() {
|
|
||||||
String sn = "1004282452";
|
|
||||||
RetWrap retWrap = api.generateDE(sn, (byte) 0x30);
|
|
||||||
String sessionKey = (String) retWrap.get("SessionKey");
|
|
||||||
String CipherKey = (String) retWrap.get("CipherKey");
|
|
||||||
String KCV = (String) retWrap.get("KCV");
|
|
||||||
|
|
||||||
RetWrap retWrap1 = api.decryptDE(sn, CipherKey);
|
|
||||||
printRetWrap(retWrap1);
|
|
||||||
}
|
|
||||||
|
|
||||||
// 测试通过
|
|
||||||
// 7E
|
|
||||||
@Test
|
|
||||||
public void testSYD_SM2_Get_Dn_PublicKey_HA() {
|
|
||||||
String dn = "C=CN,O=Sunyard,OU=8001,CN=8001";
|
|
||||||
String s = api.SYD_SM2_Get_Dn_PublicKey_HA(dn.getBytes(), 0);
|
|
||||||
System.out.println(s);
|
|
||||||
}
|
|
||||||
|
|
||||||
// 测试通过
|
|
||||||
// 6E
|
|
||||||
@Test
|
|
||||||
public void testGetX509SN() {
|
|
||||||
String dn = "C=CN,ST=ZJ,L=HZ,O=SUNYARD,OU=123456,CN=111";
|
|
||||||
String s = api.getX509SN(0, dn.getBytes());
|
|
||||||
System.out.println(s);
|
|
||||||
}
|
|
||||||
|
|
||||||
// 测试通过
|
|
||||||
// 7E
|
|
||||||
@Test
|
|
||||||
public void testGetDNPublicKey() {
|
|
||||||
String dn = "C=CN,O=Sunyard,OU=8001,CN=8001";
|
|
||||||
String s = api.GetDNPublicKey(0, dn.getBytes());
|
|
||||||
System.out.println(s);
|
|
||||||
}
|
|
||||||
|
|
||||||
// 测试通过
|
|
||||||
// QQ
|
|
||||||
@Test
|
|
||||||
public void testSM2GetPublicKeyC() {
|
|
||||||
String userId = "1111111111111117";
|
|
||||||
|
|
||||||
String s = api.SM2GetPublicKeyC(userId, 0);
|
|
||||||
System.out.println(s);
|
|
||||||
}
|
|
||||||
|
|
||||||
// 测试通过
|
|
||||||
// 8016
|
|
||||||
@Test
|
|
||||||
public void testGetX509CertInfo() {
|
|
||||||
|
|
||||||
String pCert = "-----BEGIN CERTIFICATE-----\u0007MIIC1jCCAnqgAwIBAgIFQAKAAXQwDAYIKoEcz1UBg3UFADBhMQswCQYDVQQGEwJD\u0007TjEwMC4GA1UECgwnQ2hpbmEgRmluYW5jaWFsIENlcnRpZmljYXRpb24gQXV0aG9y\u0007aXR5MSAwHgYDVQQDDBdDRkNBIEFDUyBURVNUIFNNMiBPQ0EzMTAeFw0xNzExMTYw\u0007NjU0NDVaFw0yMjExMTYwNjU0NDVaMIGDMQswCQYDVQQGEwJDTjEcMBoGA1UECgwT\u0007Q0ZDQSBURVNUIFNNMiBPQ0EzMTEOMAwGA1UECwwFU0hDUEUxGTAXBgNVBAsMEE9y\u0007Z2FuaXphdGlvbmFsLTExKzApBgNVBAMMIjA1MUDkuIrmtbfnpajmja7kuqTmmJPm\u0007iYBAQUFBQUFBQDgwWTATBgcqhkjOPQIBBggqgRzPVQGCLQNCAARg8D1RBEv9lpOE\u0007Q3SdzdLCQ4fDiE8Ncb2Fl4qIGc12GA/LUS1fgzLZuk0WlgyZDSe+QlQziqkmsXsx\u0007KoTCzqsto4H5MIH2MD8GCCsGAQUFBwEBBDMwMTAvBggrBgEFBQcwAYYjaHR0cDov\u0007L29jc3B0ZXN0LmNmY2EuY29tLmNuOjgwL29jc3AwHwYDVR0jBBgwFoAUBMe8+VkB\u0007aT6MNDYgYhg83ry1uwwwDAYDVR0TAQH/BAIwADA2BgNVHR8ELzAtMCugKaAnhiVo\u0007dHRwOi8vMjEwLjc0LjQyLjMvT0NBMzEvU00yL2NybDEuY3JsMA4GA1UdDwEB/wQE\u0007AwIGwDAdBgNVHQ4EFgQUomdLtdhENYb16pe1LNRlcr4N7b8wHQYDVR0lBBYwFAYI\u0007KwYBBQUHAwIGCCsGAQUFBwMEMAwGCCqBHM9VAYN1BQADSAAwRQIgZpJGhpRKmgfi\u0007Vbdq3UAGW6I3AUMfbWMd6webLQXmCOoCIQDSxTKRb0TfoXepD3VgO9qxCDwSc4yn\u0007WJ2GC3qmr81QBg==\u0007-----END CERTIFICATE-----\u0007";
|
|
||||||
X509 x509 = api.GetX509CertInfo(pCert);
|
|
||||||
|
|
||||||
String path = "E:\\work\\sunyard\\证书\\sm2.q\\sm2.q.enc.crt.pem";
|
|
||||||
X509 x509_1 = api.GetX509CertInfo(getCertStr(path));
|
|
||||||
}
|
|
||||||
|
|
||||||
// 测试通过
|
|
||||||
// 8017
|
|
||||||
@Test
|
|
||||||
public void testGetX509CertFileC() {
|
|
||||||
String userId = "8001";
|
|
||||||
|
|
||||||
String s = api.GetX509CertFileC(userId, 0);
|
|
||||||
System.out.println(s);
|
|
||||||
}
|
|
||||||
|
|
||||||
// 测试通过
|
|
||||||
// E2
|
|
||||||
@Test
|
|
||||||
public void testSM2GenKeyPair() {
|
|
||||||
RetWrap retWrap = api.SM2GenKeyPair();
|
|
||||||
printRetWrap(retWrap, true);
|
|
||||||
}
|
|
||||||
|
|
||||||
// 测试通过
|
|
||||||
// QN
|
|
||||||
@Test
|
|
||||||
public void testSYD_SM2GenKeyPair() {
|
|
||||||
RetWrap retWrap = api.SYD_SM2GenKeyPair();
|
|
||||||
printRetWrap(retWrap);
|
|
||||||
}
|
|
||||||
|
|
||||||
// 测试通过
|
|
||||||
// 77
|
|
||||||
@Test
|
|
||||||
public void testSM2Encrypt() {
|
|
||||||
String publicKey = "03420004C51A40A094B6A14500B2980603D68CA263FF1BA238AFB17BB8B791C5F444465A749B68B4584C83E7BEF66DE2446177E14DBE0F32691F54B1636CC73334A1A94D";
|
|
||||||
String orgData = "FFFFFFFFFFFFFFFF";
|
|
||||||
String s = api.SM2Encrypt(Util.hexString2Bytes(publicKey), orgData.getBytes());
|
|
||||||
|
|
||||||
System.out.println("encData: " + s);
|
|
||||||
}
|
|
||||||
|
|
||||||
// 测试通过
|
|
||||||
// 78
|
|
||||||
@Test
|
|
||||||
public void testSM2DecryptC() {
|
|
||||||
String certId = "1111111111111122";
|
|
||||||
String publicKey = "0342000469DE3847DD6A66DA96DB8F2DCFA32E10E680FF2EF4A592079E7C3A44320BB15084E7CA9782A39B6E28F07C04FE00D68958A2605921E71712D56C1E4435A39FA5";
|
|
||||||
String orgData = "FFFFFFFFFFFFFFFF";
|
|
||||||
String s = api.SM2Encrypt(Util.hexString2Bytes(publicKey), orgData.getBytes());
|
|
||||||
|
|
||||||
byte[] bytes = api.SM2DecryptC(certId, s);
|
|
||||||
|
|
||||||
System.out.println("decData:" + new String(bytes));
|
|
||||||
}
|
|
||||||
|
|
||||||
// 测试通过
|
|
||||||
// 76
|
|
||||||
// 带公钥
|
|
||||||
@Test
|
|
||||||
public void testSM3Hash() {
|
|
||||||
String publicKey = "0342000469DE3847DD6A66DA96DB8F2DCFA32E10E680FF2EF4A592079E7C3A44320BB15084E7CA9782A39B6E28F07C04FE00D68958A2605921E71712D56C1E4435A39FA5";
|
|
||||||
String orgData = "FFFFFFFFFFFFFFFF";
|
|
||||||
|
|
||||||
byte[] hash = api.SM3Hash(publicKey, orgData.getBytes());
|
|
||||||
|
|
||||||
System.out.println("hash:" + Util.bytes2HexString(hash));
|
|
||||||
}
|
|
||||||
|
|
||||||
// 测试通过
|
|
||||||
// 76
|
|
||||||
// 不带公钥
|
|
||||||
@Test
|
|
||||||
public void testSM3Hash2() {
|
|
||||||
String orgData = "FFFFFFFFFFFFFFFF";
|
|
||||||
|
|
||||||
byte[] hash = api.SM3Hash(orgData.getBytes());
|
|
||||||
|
|
||||||
System.out.println("hash:" + Util.bytes2HexString(hash));
|
|
||||||
}
|
|
||||||
|
|
||||||
// 工具方法
|
|
||||||
// ==========================================
|
|
||||||
|
|
||||||
public static void printRetWrap(RetWrap rw) {
|
|
||||||
printRetWrap(rw, false);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 输出
|
|
||||||
* @param rw
|
|
||||||
*/
|
|
||||||
public static void printRetWrap(RetWrap rw, boolean flag) {
|
|
||||||
for (String s : rw.keySet()) {
|
|
||||||
|
|
||||||
Object o = rw.get(s);
|
|
||||||
if (o instanceof String) {
|
|
||||||
System.out.println(s + ":" + o);
|
|
||||||
} else if (o instanceof byte[]) {
|
|
||||||
if (flag) {
|
|
||||||
System.out.println(s + ": " + Util.bytes2HexString((byte[]) o));
|
|
||||||
} else {
|
|
||||||
System.out.println(s + ": " + new String(Util.hexString2Bytes(Util.bytes2HexString((byte[]) o))));
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
System.out.println(s + ":" + o);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// 获取证书
|
|
||||||
public String getCertStr(String path) {
|
|
||||||
|
|
||||||
BufferedInputStream bis = null;
|
|
||||||
try {
|
|
||||||
bis = new BufferedInputStream(new FileInputStream(path));
|
|
||||||
|
|
||||||
StringBuilder str = new StringBuilder();
|
|
||||||
|
|
||||||
int len = 0;
|
|
||||||
|
|
||||||
while ((len = bis.read()) != -1) {
|
|
||||||
str.append((char) len);
|
|
||||||
}
|
|
||||||
|
|
||||||
return str.toString();
|
|
||||||
} catch (IOException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
} finally {
|
|
||||||
if (bis != null) {
|
|
||||||
try {
|
|
||||||
bis.close();
|
|
||||||
} catch (IOException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
14
src/test/java/lrapi/lr.java
Normal file
14
src/test/java/lrapi/lr.java
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
package lrapi;
|
||||||
|
|
||||||
|
public class lr {
|
||||||
|
|
||||||
|
public static String AUTO = "AUTO";
|
||||||
|
|
||||||
|
public static void start_transaction(String t) {
|
||||||
|
System.out.println("start_transaction" + t);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void end_transaction(String t, String type) {
|
||||||
|
System.out.println("end_transaction" + t);
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue
Block a user