Compare commits
6
Commits
5259876780
...
10d9d1b0d6
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
10d9d1b0d6 | ||
|
|
b8322538e7 | ||
|
|
83802b6ef6 | ||
|
|
9062a9c17c | ||
|
|
88f4bdf603 | ||
|
|
385e77b766 |
+2
-2
@@ -50,8 +50,8 @@
|
||||
</options>
|
||||
</error>
|
||||
|
||||
<pk len="32" cn="公钥"></pk>
|
||||
<sk len="160" cn="私钥"></sk>
|
||||
<pk len="128" cn="公钥"></pk>
|
||||
<sk len="64" cn="私钥"></sk>
|
||||
</data>
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,30 @@
|
||||
<assembly xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0
|
||||
http://maven.apache.org/xsd/assembly-1.1.0.xsd">
|
||||
<id>assembled-test-jar</id>
|
||||
<formats>
|
||||
<format>jar</format>
|
||||
</formats>
|
||||
<includeBaseDirectory>false</includeBaseDirectory>
|
||||
<fileSets>
|
||||
<!-- 打包主代码 -->
|
||||
<fileSet>
|
||||
<directory>${project.build.outputDirectory}</directory>
|
||||
<outputDirectory>/</outputDirectory>
|
||||
</fileSet>
|
||||
<!-- 打包测试代码 -->
|
||||
<fileSet>
|
||||
<directory>${project.build.testOutputDirectory}</directory>
|
||||
<outputDirectory>/</outputDirectory>
|
||||
</fileSet>
|
||||
</fileSets>
|
||||
<!-- 打包依赖的Jar包 -->
|
||||
<dependencySets>
|
||||
<dependencySet>
|
||||
<outputDirectory>/</outputDirectory>
|
||||
<unpack>true</unpack>
|
||||
<scope>runtime</scope>
|
||||
</dependencySet>
|
||||
</dependencySets>
|
||||
</assembly>
|
||||
@@ -182,22 +182,6 @@
|
||||
</executions>
|
||||
</plugin>
|
||||
|
||||
|
||||
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-jar-plugin</artifactId>
|
||||
<configuration>
|
||||
<archive>
|
||||
<manifest>
|
||||
<addClasspath>true</addClasspath>
|
||||
<classpathPrefix>lib/</classpathPrefix>
|
||||
<mainClass>com.xxx.uploadFile</mainClass>
|
||||
</manifest>
|
||||
</archive>
|
||||
</configuration>
|
||||
</plugin>
|
||||
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-dependency-plugin</artifactId>
|
||||
@@ -224,9 +208,12 @@
|
||||
<plugin>
|
||||
<artifactId>maven-assembly-plugin</artifactId>
|
||||
<configuration>
|
||||
<descriptors>
|
||||
<descriptor>assembly.xml</descriptor>
|
||||
</descriptors>
|
||||
<archive>
|
||||
<manifest>
|
||||
<mainClass>com.Sample.TestDemo</mainClass>
|
||||
<mainClass>sample.TestDemo</mainClass>
|
||||
</manifest>
|
||||
</archive>
|
||||
<descriptorRefs>
|
||||
|
||||
@@ -45,6 +45,9 @@ public class SydApiException extends RuntimeException{
|
||||
case 4:
|
||||
msg = "DER 编码格式错误(公钥) ";
|
||||
break;
|
||||
case 0xd:
|
||||
msg = "公钥加密错误";
|
||||
break;
|
||||
case 21:
|
||||
msg = "输入的数据格式错误 ";
|
||||
break;
|
||||
|
||||
@@ -51,6 +51,7 @@ import java.net.Socket;
|
||||
import java.net.SocketAddress;
|
||||
import java.net.SocketTimeoutException;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.ByteOrder;
|
||||
import java.nio.charset.Charset;
|
||||
import java.security.NoSuchProviderException;
|
||||
import java.security.Security;
|
||||
@@ -2586,49 +2587,69 @@ public class SydApi4j implements SydApi {
|
||||
|
||||
private ByteBuffer read(Socket socket) throws IOException {
|
||||
InputStream is = socket.getInputStream();
|
||||
int d;
|
||||
int high = is.read();
|
||||
int low = is.read();
|
||||
int len = (high << 8) + low;
|
||||
byte[] buf = new byte[2];
|
||||
int offset = 0;
|
||||
int remaining = 2;
|
||||
while (remaining > 0) {
|
||||
int read = is.read(buf, offset, remaining);
|
||||
if (read == -1) {
|
||||
throw new EOFException("Expected 2 bytes, but reached end of stream after reading " + offset + " byte(s)");
|
||||
}
|
||||
offset += read;
|
||||
remaining -= read;
|
||||
}
|
||||
int len = ((buf[0] & 0xFF) << 8) | (buf[1] & 0xFF);
|
||||
|
||||
len += 2;
|
||||
|
||||
if(debug){
|
||||
print("H\t");
|
||||
println(Integer.toHexString(high));
|
||||
print("L\t");
|
||||
println(Integer.toHexString(low));
|
||||
print("Len\t");
|
||||
print("接收数据\t");
|
||||
// print("H=");
|
||||
// print(Integer.toHexString(high));
|
||||
// print("\tL=");
|
||||
// print(Integer.toHexString(low));
|
||||
print("\tLen=");
|
||||
println(len);
|
||||
}
|
||||
|
||||
|
||||
ByteBuffer bb = ByteBuffer.allocate(len);
|
||||
bb.put((byte) (high & 0xFF));
|
||||
bb.put(buf);
|
||||
// bb.put((byte) (high & 0xFF));
|
||||
//println(String.format("%d %d %s",len, bb.position() -1, Util.bytes2HexString(new byte[]{(byte) (high & 0xFF)})));
|
||||
|
||||
bb.put((byte) (low & 0xFF));
|
||||
// bb.put((byte) (low & 0xFF));
|
||||
//println(String.format("%d %d %s",len, bb.position() -1, Util.bytes2HexString(new byte[]{(byte) (low & 0xFF)})));
|
||||
|
||||
// int d = 0;
|
||||
// while (true) {
|
||||
// d = is.read();
|
||||
// if (-1 == d) {
|
||||
// break;
|
||||
// }
|
||||
//
|
||||
// bb.put((byte) (d & 0xFF));
|
||||
//
|
||||
// //println(String.format("%d %d %s",len, bb.position() -1, Util.bytes2HexString(new byte[]{(byte) (d & 0xFF)})));
|
||||
//
|
||||
// if (bb.position() == len) {
|
||||
// break;
|
||||
// }
|
||||
// }
|
||||
remaining = len - bb.position(); // 还需要读取的字节数
|
||||
byte[] buffer = new byte[8192]; // 批量读取缓冲区
|
||||
|
||||
while (true) {
|
||||
d = is.read();
|
||||
if (-1 == d) {
|
||||
break;
|
||||
}
|
||||
|
||||
bb.put((byte) (d & 0xFF));
|
||||
|
||||
//println(String.format("%d %d %s",len, bb.position() -1, Util.bytes2HexString(new byte[]{(byte) (d & 0xFF)})));
|
||||
|
||||
if (bb.position() == len) {
|
||||
break;
|
||||
while (remaining > 0) {
|
||||
int toRead = Math.min(remaining, buffer.length);
|
||||
int bytesRead = is.read(buffer, 0, toRead);
|
||||
if (bytesRead == -1) {
|
||||
// 与原逻辑不同:这里抛异常,而不是静默退出
|
||||
throw new EOFException("Unexpected end of stream; expected " + remaining + " more bytes");
|
||||
}
|
||||
bb.put(buffer, 0, bytesRead);
|
||||
remaining -= bytesRead;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
if (null != builder && builder.isUseEBCDMode()) {
|
||||
// print("EBCD 数据: \t");
|
||||
// println(Util.bytes2HexString(bb.array()));
|
||||
@@ -2662,8 +2683,10 @@ public class SydApi4j implements SydApi {
|
||||
ByteBuffer bb = read(socket);
|
||||
return bb;
|
||||
|
||||
} catch (SocketTimeoutException e) {
|
||||
throw new SydApiException("接收数据超时", -2);
|
||||
} catch (EOFException e) {
|
||||
throw new SydApiException("接收数据不完整", -21, e);
|
||||
}catch (SocketTimeoutException e) {
|
||||
throw new SydApiException("接收数据超时", -2, e);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
@@ -6901,18 +6924,18 @@ public class SydApi4j implements SydApi {
|
||||
bb.put("7F".getBytes());
|
||||
bb.put((byte) dataType); // 数据包标志
|
||||
if ( 2 == dataType ) { // 公钥
|
||||
bb.put(ByteUtil.shortToBytes((short) publicKey.length));
|
||||
bb.put(ByteUtil.shortToBytes((short) publicKey.length, ByteOrder.BIG_ENDIAN) );
|
||||
bb.put(publicKey);
|
||||
}
|
||||
if ( 1 == dataType ) { // 数据
|
||||
bb.put(ByteUtil.shortToBytes((short) pOrgData.limit()));
|
||||
bb.put(ByteUtil.shortToBytes((short) pOrgData.limit(), ByteOrder.BIG_ENDIAN));
|
||||
bb.put(pOrgData);
|
||||
bb.put(ByteUtil.shortToBytes((short)idx));
|
||||
bb.put(ByteUtil.intToBytes(idx));
|
||||
}
|
||||
|
||||
if ( 3 == dataType) { // 仅数据长度
|
||||
bb.put( ByteUtil.shortToBytes((short) (63*1024)) );
|
||||
bb.put( ByteUtil.shortToBytes((short)idx));
|
||||
bb.put( ByteUtil.shortToBytes((short) (63*1024), ByteOrder.BIG_ENDIAN) );
|
||||
bb.put( ByteUtil.intToBytes(idx, ByteOrder.BIG_ENDIAN));
|
||||
}
|
||||
|
||||
|
||||
@@ -6943,7 +6966,7 @@ public class SydApi4j implements SydApi {
|
||||
int isLast = bb.get();
|
||||
byte[] dataLenArr = new byte[2];
|
||||
bb.get(dataLenArr);
|
||||
int dataLen = ByteUtil.bytesToInt(dataLenArr);
|
||||
int dataLen = ByteUtil.bytesToInt(dataLenArr, ByteOrder.BIG_ENDIAN);
|
||||
// byte[] data = new byte[dataLen];
|
||||
// bb.get(data);
|
||||
ByteBuffer slice = ByteBufferUtil.sliceAndConsume(bb, dataLen);
|
||||
@@ -7036,17 +7059,17 @@ public class SydApi4j implements SydApi {
|
||||
bb.put((byte) dataType);
|
||||
|
||||
if (dataType == 2) { // 私钥
|
||||
bb.put(ByteUtil.shortToBytes((short) privateKey.length));
|
||||
bb.put(ByteUtil.shortToBytes((short) privateKey.length, ByteOrder.BIG_ENDIAN));
|
||||
bb.put(privateKey);
|
||||
}
|
||||
if (dataType == 1) { // 密文块
|
||||
bb.put(ByteUtil.shortToBytes((short) pCipherData.limit()));
|
||||
bb.put(ByteUtil.shortToBytes((short) pCipherData.limit(), ByteOrder.BIG_ENDIAN));
|
||||
bb.put(pCipherData);
|
||||
bb.put(ByteUtil.shortToBytes((short) idx));
|
||||
bb.put(ByteUtil.intToBytes(idx, ByteOrder.BIG_ENDIAN));
|
||||
}
|
||||
if (dataType == 3) { // 请求明文块
|
||||
bb.put(ByteUtil.shortToBytes((short) (63 * 1024)));
|
||||
bb.put(ByteUtil.shortToBytes((short) idx));
|
||||
bb.put(ByteUtil.shortToBytes((short) (63 * 1024), ByteOrder.BIG_ENDIAN));
|
||||
bb.put(ByteUtil.intToBytes(idx, ByteOrder.BIG_ENDIAN));
|
||||
}
|
||||
|
||||
// 填写总长度(长度字段本身不包含在内)
|
||||
@@ -7073,7 +7096,7 @@ public class SydApi4j implements SydApi {
|
||||
int isLast = bb.get();
|
||||
byte[] dataLenArr = new byte[2];
|
||||
bb.get(dataLenArr);
|
||||
int dataLen = ByteUtil.bytesToInt(dataLenArr);
|
||||
int dataLen = ByteUtil.bytesToInt(dataLenArr, ByteOrder.BIG_ENDIAN);
|
||||
ByteBuffer slice = ByteBufferUtil.sliceAndConsume(bb, dataLen);
|
||||
return new MutiReturn7(retCode, isLast, slice);
|
||||
} else {
|
||||
|
||||
@@ -1,29 +1,44 @@
|
||||
package cmbpoc;
|
||||
|
||||
import com.sunyard.RetWrap;
|
||||
import com.sunyard.SydApi;
|
||||
import com.sunyard.proto.PacketSection;
|
||||
import com.sunyard.proto.Util;
|
||||
import org.junit.After;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.*;
|
||||
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 String keypairIndex4Ende = "0000000000000sge00100000001";
|
||||
private byte[] privateKey4Sign;
|
||||
private byte[] publicKey4Sign;
|
||||
private byte[] privateKey4Ende;
|
||||
private byte[] publicKey4Ende;
|
||||
private byte[] orgData = new byte[15];
|
||||
private String sign;
|
||||
|
||||
@Before
|
||||
public void start(){
|
||||
// 调试模式
|
||||
|
||||
System.setProperty("com.sunyard.sydapi4j.debug", "true");
|
||||
|
||||
// 建立链接(单台)
|
||||
this.api = (SydApi4j) new SydApi4j().connect("192.168.0.100", 8889, null, 1000);
|
||||
this.api = (SydApi4j) new SydApi4j().connect("192.168.100.145", 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() );
|
||||
|
||||
|
||||
this.publicKey4Ende = Util.hexString2Bytes("03420004AF3D4E55D26564C6C937E6EA9232691C01AC5E7916AD2136F788CE7C1E4D0AE8C4754DEC2F7F6A78962D51A171A6F5B4F11823390AEC8B5B0246CD2CCF8052B7");
|
||||
this.privateKey4Ende = Util.hexString2Bytes("00010000963F7C3A98B7810F52D2861A060E18A9D4D59796CF33967DD61EEDA091E1AD9B0000000000000000000000000000000000000000000000000000000000000000");
|
||||
}
|
||||
|
||||
|
||||
@@ -37,35 +52,56 @@ public class FunctionTest {
|
||||
|
||||
|
||||
|
||||
@Ignore
|
||||
@Test
|
||||
public void getPrivateKeyAndPublickKey(){
|
||||
this.publicKey = Util.hexString2Bytes(
|
||||
this.api.SM2GetPublicKeyC(keypairIndex)
|
||||
);
|
||||
public void genKeyPair(){
|
||||
// RetWrap r = this.api.SYD_SM2GenKeyPair();
|
||||
// String pk = r.get("publicKey").toString();
|
||||
// String sk = r.get("privateKey").toString();
|
||||
//
|
||||
// System.out.println("pk=" + pk);
|
||||
// System.out.println("sk=" + sk);
|
||||
//
|
||||
// this.privateKey4Sign = Util.hexString2Bytes(sk);
|
||||
// this.publicKey4Sign = Util.hexString2Bytes(pk);
|
||||
|
||||
RetWrap rw = this.api.SM2GenKeyPair();
|
||||
byte[] pk = (byte[]) rw.get(SydApi.RET_PUBLIC_KEY);
|
||||
byte[] sk = (byte[]) rw.get(SydApi.RET_PRIVATE_KEY);
|
||||
System.out.println("pk=" + Util.bytes2HexString(pk));
|
||||
System.out.println("sk=" + Util.bytes2HexString(sk));
|
||||
}
|
||||
|
||||
|
||||
this.privateKey = Util.hexString2Bytes(
|
||||
this.api.SM2GetPrivateKeyC(keypairIndex)
|
||||
);
|
||||
public RetWrap getPrivateKeyAndPublickKey(String keypairIndex){
|
||||
String pk = this.api.SM2GetPublicKeyC(keypairIndex);
|
||||
String sk = this.api.SM2GetPrivateKeyC(keypairIndex);
|
||||
|
||||
System.out.println("pk=" + pk);
|
||||
System.out.println("sk=" + sk);
|
||||
|
||||
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_SM2_Encrypt(publicKey, orgData);
|
||||
byte[] deData = this.api.SYD_SM2Decrypt(privateKey, enData);
|
||||
Assert.assertArrayEquals(enData, deData);
|
||||
byte[] enData = this.api.SYD_SM2Encrypt(publicKey4Ende, orgData);
|
||||
// byte[] deData = this.api.SYD_SM2Decrypt(publicKey4Ende, enData);
|
||||
// Assert.assertArrayEquals(enData, deData);
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -6,8 +6,6 @@ import org.apache.jmeter.protocol.java.sampler.AbstractJavaSamplerClient;
|
||||
import org.apache.jmeter.protocol.java.sampler.JavaSamplerContext;
|
||||
import org.apache.jmeter.samplers.SampleResult;
|
||||
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.Base64;
|
||||
|
||||
public class JmeterTest extends AbstractJavaSamplerClient {
|
||||
|
||||
@@ -18,19 +16,13 @@ public class JmeterTest extends AbstractJavaSamplerClient {
|
||||
@Override
|
||||
public Arguments getDefaultParameters() {
|
||||
Arguments params = new Arguments();
|
||||
params.addArgument("publicKeyBase64", "MFkwEwYHKoZIzj0CAQYIKoEcz1UBgi0DQgAE...");
|
||||
params.addArgument("plainText", "Hello JMeter");
|
||||
params.addArgument("function", "sleep");
|
||||
params.addArgument("sleep", "1");
|
||||
return params;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setupTest(JavaSamplerContext context) {
|
||||
// 初始化:将 Base64 参数转为字节数组,避免每个循环都转换
|
||||
String pubBase64 = context.getParameter("publicKeyBase64");
|
||||
String plainText = context.getParameter("plainText");
|
||||
publicKey = Base64.getDecoder().decode(pubBase64);
|
||||
plainData = plainText.getBytes(StandardCharsets.UTF_8);
|
||||
|
||||
// 校准测试
|
||||
sleep = context.getIntParameter("sleep", 1);
|
||||
|
||||
@@ -57,7 +49,7 @@ public class JmeterTest extends AbstractJavaSamplerClient {
|
||||
case "SYD_SM2_Sign":
|
||||
break;
|
||||
case "sleep":
|
||||
Thread.sleep(1);
|
||||
Thread.sleep( this.sleep );
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
|
||||
@@ -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.0.100", 8889, null, 1000);
|
||||
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();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
+3
-3
@@ -1,6 +1,6 @@
|
||||
package com.jmeter.test;
|
||||
package jmeter;
|
||||
|
||||
import com.Sample.SydUtils;
|
||||
import sample.SydUtils;
|
||||
import com.google.gson.Gson;
|
||||
import com.sunyard.SydApiException;
|
||||
import com.sunyard.entity.ImportResult;
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.Sample;
|
||||
package sample;
|
||||
|
||||
import racal.sunyard.main.SydApi4j;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.sample;
|
||||
package sample;
|
||||
|
||||
import cn.hutool.core.io.FileUtil;
|
||||
import cn.hutool.json.JSONObject;
|
||||
@@ -1,10 +1,7 @@
|
||||
package sample;
|
||||
|
||||
import cn.hutool.core.date.StopWatch;
|
||||
import com.Sample.SydUtils;
|
||||
import com.google.gson.Gson;
|
||||
import com.sunyard.RetWrap;
|
||||
import com.sunyard.SydApi;
|
||||
import com.sunyard.SydApiException;
|
||||
import com.sunyard.entity.ImportResult;
|
||||
import com.sunyard.proto.Util;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.Sample;
|
||||
package sample;
|
||||
|
||||
import com.sunyard.RetWrap;
|
||||
import com.sunyard.proto.Util;
|
||||
Reference in New Issue
Block a user