调整协议,index 改为 4 字节。
This commit is contained in:
parent
5259876780
commit
385e77b766
@ -6907,12 +6907,12 @@ public class SydApi4j implements SydApi {
|
|||||||
if ( 1 == dataType ) { // 数据
|
if ( 1 == dataType ) { // 数据
|
||||||
bb.put(ByteUtil.shortToBytes((short) pOrgData.limit()));
|
bb.put(ByteUtil.shortToBytes((short) pOrgData.limit()));
|
||||||
bb.put(pOrgData);
|
bb.put(pOrgData);
|
||||||
bb.put(ByteUtil.shortToBytes((short)idx));
|
bb.put(ByteUtil.intToBytes(idx));
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( 3 == dataType) { // 仅数据长度
|
if ( 3 == dataType) { // 仅数据长度
|
||||||
bb.put( ByteUtil.shortToBytes((short) (63*1024)) );
|
bb.put( ByteUtil.shortToBytes((short) (63*1024)) );
|
||||||
bb.put( ByteUtil.shortToBytes((short)idx));
|
bb.put( ByteUtil.intToBytes(idx));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -7042,11 +7042,11 @@ public class SydApi4j implements SydApi {
|
|||||||
if (dataType == 1) { // 密文块
|
if (dataType == 1) { // 密文块
|
||||||
bb.put(ByteUtil.shortToBytes((short) pCipherData.limit()));
|
bb.put(ByteUtil.shortToBytes((short) pCipherData.limit()));
|
||||||
bb.put(pCipherData);
|
bb.put(pCipherData);
|
||||||
bb.put(ByteUtil.shortToBytes((short) idx));
|
bb.put(ByteUtil.intToBytes(idx));
|
||||||
}
|
}
|
||||||
if (dataType == 3) { // 请求明文块
|
if (dataType == 3) { // 请求明文块
|
||||||
bb.put(ByteUtil.shortToBytes((short) (63 * 1024)));
|
bb.put(ByteUtil.shortToBytes((short) (63 * 1024)));
|
||||||
bb.put(ByteUtil.shortToBytes((short) idx));
|
bb.put(ByteUtil.intToBytes(idx));
|
||||||
}
|
}
|
||||||
|
|
||||||
// 填写总长度(长度字段本身不包含在内)
|
// 填写总长度(长度字段本身不包含在内)
|
||||||
|
|||||||
@ -1,10 +1,8 @@
|
|||||||
package cmbpoc;
|
package cmbpoc;
|
||||||
|
|
||||||
|
import com.sunyard.RetWrap;
|
||||||
import com.sunyard.proto.Util;
|
import com.sunyard.proto.Util;
|
||||||
import org.junit.After;
|
import org.junit.*;
|
||||||
import org.junit.Assert;
|
|
||||||
import org.junit.Before;
|
|
||||||
import org.junit.Test;
|
|
||||||
import racal.sunyard.main.SydApi4j;
|
import racal.sunyard.main.SydApi4j;
|
||||||
|
|
||||||
public class FunctionTest {
|
public class FunctionTest {
|
||||||
@ -22,7 +20,7 @@ public class FunctionTest {
|
|||||||
System.setProperty("com.sunyard.sydapi4j.debug", "true");
|
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.21.166", 8889, null, 1000);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -37,13 +35,29 @@ 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();
|
||||||
|
|
||||||
|
System.out.println("pk=" + pk);
|
||||||
|
System.out.println("sk=" + sk);
|
||||||
|
|
||||||
|
this.privateKey = Util.hexString2Bytes(sk);
|
||||||
|
this.publicKey = Util.hexString2Bytes(pk);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@Ignore
|
||||||
@Test
|
@Test
|
||||||
public void getPrivateKeyAndPublickKey(){
|
public void getPrivateKeyAndPublickKey(){
|
||||||
this.publicKey = Util.hexString2Bytes(
|
this.publicKey = Util.hexString2Bytes(
|
||||||
this.api.SM2GetPublicKeyC(keypairIndex)
|
this.api.SM2GetPublicKeyC(keypairIndex)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
||||||
this.privateKey = Util.hexString2Bytes(
|
this.privateKey = Util.hexString2Bytes(
|
||||||
this.api.SM2GetPrivateKeyC(keypairIndex)
|
this.api.SM2GetPrivateKeyC(keypairIndex)
|
||||||
);
|
);
|
||||||
@ -61,7 +75,7 @@ public class FunctionTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void SYD_SM2_Encrypt(){
|
public void SYD_SM2_Encrypt(){
|
||||||
byte[] enData = this.api.SYD_SM2_Encrypt(publicKey, orgData);
|
byte[] enData = this.api.SYD_SM2Encrypt(publicKey, orgData);
|
||||||
byte[] deData = this.api.SYD_SM2Decrypt(privateKey, enData);
|
byte[] deData = this.api.SYD_SM2Decrypt(privateKey, enData);
|
||||||
Assert.assertArrayEquals(enData, deData);
|
Assert.assertArrayEquals(enData, deData);
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user