测试代码整理
This commit is contained in:
parent
48d9719fbc
commit
12b53a2e0f
@ -8,10 +8,12 @@ import racal.sunyard.main.SydApi4j;
|
||||
public class FunctionTest {
|
||||
|
||||
private SydApi4j api;
|
||||
private String keypairIndex;
|
||||
private byte[] privateKey;
|
||||
private byte[] publicKey;
|
||||
private byte[] orgData;
|
||||
private String keypairIndex4Sign = "0000000000000sge00000000001";
|
||||
private byte[] privateKey4Sign;
|
||||
private byte[] publicKey4Sign;
|
||||
private byte[] privateKey4Ende;
|
||||
private byte[] publicKey4Ende;
|
||||
private byte[] orgData = new byte[2 * 1024];
|
||||
private String sign;
|
||||
|
||||
@Before
|
||||
@ -20,8 +22,15 @@ public class FunctionTest {
|
||||
System.setProperty("com.sunyard.sydapi4j.debug", "true");
|
||||
|
||||
// 建立链接(单台)
|
||||
this.api = (SydApi4j) new SydApi4j().connect("192.168.21.166", 8889, null, 5000);
|
||||
this.api = (SydApi4j) new SydApi4j().connect("172.1.41.139", 8889, null, 5000);
|
||||
|
||||
RetWrap keypair = this.getPrivateKeyAndPublickKey(keypairIndex4Sign);
|
||||
this.publicKey4Sign = Util.hexString2Bytes( keypair.get("pk").toString() );
|
||||
this.privateKey4Sign = Util.hexString2Bytes( keypair.get("sk").toString() );
|
||||
|
||||
RetWrap keypair4Ende = this.getPrivateKeyAndPublickKey(keypairIndex4Sign);
|
||||
this.publicKey4Ende = Util.hexString2Bytes( keypair4Ende.get("pk").toString() );
|
||||
this.privateKey4Ende = Util.hexString2Bytes( keypair4Ende.get("sk").toString() );
|
||||
}
|
||||
|
||||
|
||||
@ -45,41 +54,38 @@ public class FunctionTest {
|
||||
System.out.println("pk=" + pk);
|
||||
System.out.println("sk=" + sk);
|
||||
|
||||
this.privateKey = Util.hexString2Bytes(sk);
|
||||
this.publicKey = Util.hexString2Bytes(pk);
|
||||
this.privateKey4Sign = Util.hexString2Bytes(sk);
|
||||
this.publicKey4Sign = Util.hexString2Bytes(pk);
|
||||
}
|
||||
|
||||
|
||||
public RetWrap getPrivateKeyAndPublickKey(String keypairIndex){
|
||||
String pk = this.api.SM2GetPublicKeyC(keypairIndex);
|
||||
String sk = this.api.SM2GetPrivateKeyC(keypairIndex);
|
||||
|
||||
@Ignore
|
||||
@Test
|
||||
public void getPrivateKeyAndPublickKey(){
|
||||
this.publicKey = Util.hexString2Bytes(
|
||||
this.api.SM2GetPublicKeyC(keypairIndex)
|
||||
);
|
||||
System.out.println("pk=" + pk);
|
||||
System.out.println("sk=" + sk);
|
||||
|
||||
this.privateKey = Util.hexString2Bytes(
|
||||
this.api.SM2GetPrivateKeyC(keypairIndex)
|
||||
);
|
||||
RetWrap retWrap = new RetWrap();
|
||||
retWrap.put("pk", pk);
|
||||
retWrap.put("sk", sk);
|
||||
return retWrap;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Test
|
||||
public void SYD_SM2_Sign(){
|
||||
this.api.SYD_SM2_Sign_HA(1, privateKey, publicKey, orgData);
|
||||
this.api.SYD_SM2_Verify_HA(1, publicKey, orgData, sign);
|
||||
String sign = this.api.SYD_SM2_Sign_HA(1, privateKey4Sign, publicKey4Sign, orgData);
|
||||
this.api.SYD_SM2_Verify_HA(1, publicKey4Sign, orgData, sign);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Test
|
||||
public void SYD_SM2_Encrypt(){
|
||||
byte[] enData = this.api.SYD_SM2Encrypt(publicKey, orgData);
|
||||
byte[] deData = this.api.SYD_SM2Decrypt(privateKey, enData);
|
||||
byte[] enData = this.api.SYD_SM2Encrypt(privateKey4Ende, orgData);
|
||||
byte[] deData = this.api.SYD_SM2Decrypt(publicKey4Ende, enData);
|
||||
Assert.assertArrayEquals(enData, deData);
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
@ -18,9 +18,9 @@ public class SignatureVerifyTest {
|
||||
@Before
|
||||
public void setUp() {
|
||||
System.setProperty("com.sunyard.sydapi4j.debug", "true");
|
||||
this.api = (SydApi4j) new SydApi4j().connect("192.168.21.166", 8889, null, 2000);
|
||||
this.api = (SydApi4j) new SydApi4j().connect("172.1.41.139", 8889, null, 3000);
|
||||
this.orgData = "Hello, World! 测试数据".getBytes();
|
||||
this.SM2dn = "C=CN,ST=北京,L=北京,O=信雅达,CN=172.1.40.188";
|
||||
this.SM2dn = "C=cn,O=CFCA OCA1 SM2,OU=Local RA OCA1,OU=Units,CN=041@N91330108762038374D@sunyard@00000064";
|
||||
}
|
||||
|
||||
@After
|
||||
@ -71,7 +71,7 @@ public class SignatureVerifyTest {
|
||||
|
||||
byte[] cipherKey = (byte[]) genResult.get(SydApi.RET_CIPHER_KEY);
|
||||
Assert.assertNotNull("数字信封密文密钥不应为空", cipherKey);
|
||||
System.out.println("数字信封密文密钥: " + new String(cipherKey));
|
||||
System.out.println("数字信封密文: " + new String(cipherKey));
|
||||
|
||||
RetWrap decryptResult = this.api.decryptDEByDN(SM2dn, cipherKey);
|
||||
Assert.assertNotNull("数字信封解密结果不应为空", decryptResult);
|
||||
|
||||
@ -1,50 +0,0 @@
|
||||
package com.sunyard.sydapi.loadrunner;
|
||||
|
||||
import com.sunyard.sydapi.loadrunner.action1.Actions;
|
||||
import racal.sunyard.main.SydApi4j;
|
||||
import racal.sunyard.main.SydApiBuilder;
|
||||
|
||||
public class ShangTest {
|
||||
|
||||
private static final String dn = "C=CN,O=CFCA OCA1,OU=YCCA,OU=Individual-2,CN=YCCA@黄金交易所@Zhuangj@1";
|
||||
private static final byte[] testData = new byte[ 4 * 1024 ];
|
||||
|
||||
private SydApi4j api = null;
|
||||
|
||||
public void init() throws Exception {
|
||||
if ( null == api ) {
|
||||
api = (SydApi4j) new SydApiBuilder()
|
||||
.setIp("172.16.18.59") // 192.168.0.162
|
||||
.setPort( 8889 )
|
||||
.useDebugMode()
|
||||
.build();
|
||||
}
|
||||
}
|
||||
|
||||
public void action(){
|
||||
String sign = api.attachedSign(testData, dn);
|
||||
boolean ret = api.attachedVerify( sign );
|
||||
|
||||
assert ret;
|
||||
|
||||
}
|
||||
|
||||
public void end(){
|
||||
if (null != this.api ) {
|
||||
this.api.disconnect();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static void main(String[] args) throws Throwable {
|
||||
System.out.println( SydApi4j.getVersion() );
|
||||
|
||||
// Actions test = new Actions();
|
||||
ShangTest test = new ShangTest();
|
||||
test.init();
|
||||
test.action();
|
||||
test.end();
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@ -1,44 +0,0 @@
|
||||
package com.sunyard.sydapi.loadrunner.action1;
|
||||
|
||||
/*
|
||||
* LoadRunner Java script. (Build: _build_number_)
|
||||
*
|
||||
* Script Description:
|
||||
*
|
||||
*/
|
||||
import racal.sunyard.main.SydApi4j;
|
||||
import racal.sunyard.main.SydApiBuilder;
|
||||
|
||||
public class Actions
|
||||
{
|
||||
|
||||
private static final byte[] testData = new byte[ 4 * 1024 ];
|
||||
|
||||
private SydApi4j api = null;
|
||||
|
||||
public int init() throws Throwable {
|
||||
if ( null == api ) {
|
||||
api = (SydApi4j) new SydApiBuilder()
|
||||
.setIp("172.16.18.59")
|
||||
.setPort( 8889 )
|
||||
.useDebugMode()
|
||||
.build();
|
||||
}
|
||||
|
||||
return 0;
|
||||
}//end of init
|
||||
|
||||
|
||||
public int action() throws Throwable {
|
||||
api.SM3Hash( testData );
|
||||
return 0;
|
||||
}//end of action
|
||||
|
||||
|
||||
public int end() throws Throwable {
|
||||
if (null != this.api ) {
|
||||
this.api.disconnect();
|
||||
}
|
||||
return 0;
|
||||
}//end of end
|
||||
}
|
||||
@ -1,75 +0,0 @@
|
||||
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();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@ -1,76 +0,0 @@
|
||||
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,4 +1,4 @@
|
||||
package test;
|
||||
package jmeter;
|
||||
|
||||
import sample.SydUtils;
|
||||
import com.google.gson.Gson;
|
||||
@ -17,7 +17,7 @@ import java.nio.charset.StandardCharsets;
|
||||
import java.util.*;
|
||||
|
||||
|
||||
public class Test4Jemter extends AbstractJavaSamplerClient {
|
||||
public class Test4Jmeter extends AbstractJavaSamplerClient {
|
||||
|
||||
private String SM2dn ;
|
||||
private String RSAdn ;
|
||||
@ -1,14 +0,0 @@
|
||||
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