优化通信
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
package cmbpoc;
|
||||
|
||||
import com.sunyard.RetWrap;
|
||||
import com.sunyard.SydApi;
|
||||
import com.sunyard.proto.PacketSection;
|
||||
import com.sunyard.proto.Util;
|
||||
import org.junit.*;
|
||||
import racal.sunyard.main.SydApi4j;
|
||||
@@ -14,7 +16,7 @@ public class FunctionTest {
|
||||
private byte[] publicKey4Sign;
|
||||
private byte[] privateKey4Ende;
|
||||
private byte[] publicKey4Ende;
|
||||
private byte[] orgData = new byte[2 * 1024];
|
||||
private byte[] orgData = new byte[15];
|
||||
private String sign;
|
||||
|
||||
@Before
|
||||
@@ -24,15 +26,19 @@ public class FunctionTest {
|
||||
System.setProperty("com.sunyard.sydapi4j.debug", "true");
|
||||
|
||||
// 建立链接(单台)
|
||||
this.api = (SydApi4j) new SydApi4j().connect("172.1.41.139", 8889, null, 5000);
|
||||
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 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() );
|
||||
|
||||
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");
|
||||
}
|
||||
|
||||
|
||||
@@ -49,15 +55,21 @@ public class FunctionTest {
|
||||
@Ignore
|
||||
@Test
|
||||
public void genKeyPair(){
|
||||
RetWrap r = this.api.SYD_SM2GenKeyPair();
|
||||
String pk = r.get("publicKey").toString();
|
||||
String sk = r.get("privateKey").toString();
|
||||
// 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);
|
||||
|
||||
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));
|
||||
}
|
||||
|
||||
|
||||
@@ -86,8 +98,10 @@ public class FunctionTest {
|
||||
|
||||
@Test
|
||||
public void SYD_SM2_Encrypt(){
|
||||
byte[] enData = this.api.SYD_SM2Encrypt(privateKey4Ende, orgData);
|
||||
byte[] enData = this.api.SYD_SM2Encrypt(publicKey4Ende, orgData);
|
||||
// byte[] deData = this.api.SYD_SM2Decrypt(publicKey4Ende, enData);
|
||||
// Assert.assertArrayEquals(enData, deData);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user