73 lines
1.4 KiB
Java
73 lines
1.4 KiB
Java
package cmbpoc;
|
|
|
|
import com.sunyard.proto.Util;
|
|
import org.junit.After;
|
|
import org.junit.Before;
|
|
import org.junit.Test;
|
|
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 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);
|
|
|
|
}
|
|
|
|
|
|
@After
|
|
public void stop(){
|
|
if ( null != api ) {
|
|
this.api.disconnect();
|
|
this.api = null;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
public void getPrivateKeyAndPublickKey(){
|
|
this.publicKey = Util.hexString2Bytes(
|
|
this.api.SM2GetPublicKeyC(keypairIndex)
|
|
);
|
|
|
|
|
|
this.privateKey = Util.hexString2Bytes(
|
|
this.api.SM2GetPrivateKeyC(keypairIndex)
|
|
);
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
public void SYD_SM2_Sign(){
|
|
this.api.SYD_SM2_Sign_HA(1, privateKey, publicKey, orgData);
|
|
}
|
|
|
|
|
|
@Test
|
|
public void SYD_SM2_Verify(){
|
|
this.api.SYD_SM2_Verify_HA(1, publicKey, orgData, sign);
|
|
}
|
|
|
|
|
|
@Test
|
|
public void SYD_SM2_Encrypt(){
|
|
this.api.SM2Decrypt();
|
|
}
|
|
|
|
|
|
|
|
}
|