添加测试,修改Y8获取随机数长度

This commit is contained in:
zhoubin 2021-11-17 14:03:56 +08:00
parent 0ae7b29514
commit db746655f4
5 changed files with 71 additions and 13 deletions

View File

@ -61,7 +61,7 @@
</res> </res>
<script>function getRandomSize(){ <script>function getRandomSize(){
var data = $packet.data; var data = $packet.data;
return data.nRandomSize; return data.nRandomSize * 2;
} }
</script> </script>

Binary file not shown.

View File

@ -18,6 +18,14 @@
</properties> </properties>
<dependencies> <dependencies>
<!-- https://mvnrepository.com/artifact/org.apache.commons/commons-pool2 -->
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-pool2</artifactId>
<version>2.11.1</version>
</dependency>
<dependency> <dependency>
<groupId>junit</groupId> <groupId>junit</groupId>
<artifactId>junit</artifactId> <artifactId>junit</artifactId>

View File

@ -4513,8 +4513,8 @@ public class SydApi4j implements SydApi {
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); e.printStackTrace();
} }
BufferedInputStream fis =null; BufferedInputStream fis = null;
BufferedOutputStream fos=null; BufferedOutputStream fos = null;
try { try {
fis = new BufferedInputStream(new FileInputStream(in)); fis = new BufferedInputStream(new FileInputStream(in));
@ -4614,6 +4614,7 @@ public class SydApi4j implements SydApi {
} }
// 测试通过
@Override @Override
public byte[] SYMEncryptDataCBC(int nAlg, String seesionKey, int fullmode, byte[] pInData) { public byte[] SYMEncryptDataCBC(int nAlg, String seesionKey, int fullmode, byte[] pInData) {
if (2 == nAlg && 'L' != seesionKey.charAt(0)) { if (2 == nAlg && 'L' != seesionKey.charAt(0)) {
@ -4660,6 +4661,7 @@ public class SydApi4j implements SydApi {
return SYMDecryptDataCBC(nAlg, seesionKey, 1, pInData); return SYMDecryptDataCBC(nAlg, seesionKey, 1, pInData);
} }
// 测试通过
@Override @Override
public byte[] SYMDecryptDataCBC(int nAlg, String seesionKey, int fullmode, byte[] pInData) { public byte[] SYMDecryptDataCBC(int nAlg, String seesionKey, int fullmode, byte[] pInData) {
if (2 == nAlg && 'L' != seesionKey.charAt(0)) { if (2 == nAlg && 'L' != seesionKey.charAt(0)) {
@ -5278,8 +5280,8 @@ public class SydApi4j implements SydApi {
* 生成一个MAC * 生成一个MAC
* @param alg 算法,0=DES 1=3DES 2=SM4 3=AES 4=IDEA 5=SM1 6=3DES-X9.19 * @param alg 算法,0=DES 1=3DES 2=SM4 3=AES 4=IDEA 5=SM1 6=3DES-X9.19
* @param keyType 密钥类型,0-TAK 1-ZAK * @param keyType 密钥类型,0-TAK 1-ZAK
* @param fullMode 填充类型,0-弱填充 1 强填充
* @param AK 密钥 * @param AK 密钥
* @param fullMode 填充类型,0-弱填充 1 强填充
* @param infoData MAC数据 * @param infoData MAC数据
* @param macLen MAC数据长度,1=4Byte 2=8Byte 3=16Byte仅在SM4/AES 下有效 * @param macLen MAC数据长度,1=4Byte 2=8Byte 3=16Byte仅在SM4/AES 下有效
* @return mac hex 格式 * @return mac hex 格式
@ -5338,8 +5340,8 @@ public class SydApi4j implements SydApi {
* *
* @param alg 算法,0=DES 1=3DES 2=SM4 3=AES 4=IDEA 5=SM1 6=3DES-X9.19 * @param alg 算法,0=DES 1=3DES 2=SM4 3=AES 4=IDEA 5=SM1 6=3DES-X9.19
* @param keyType 密钥类型,0-TAK 1-ZAK * @param keyType 密钥类型,0-TAK 1-ZAK
* @param fullMode 填充类型,0-弱填充 1 强填充
* @param AK 密钥 * @param AK 密钥
* @param fullMode 填充类型,0-弱填充 1 强填充
* @param infoData MAC数据 * @param infoData MAC数据
* @param mac MAC值 hex 格式 * @param mac MAC值 hex 格式
* @return * @return

View File

@ -9,6 +9,7 @@ import org.junit.After;
import org.junit.Before; import org.junit.Before;
import org.junit.Test; import org.junit.Test;
import racal.sunyard.main.SydApi4j; import racal.sunyard.main.SydApi4j;
import racal.sunyard.main.SydApiBuilder;
import java.io.*; import java.io.*;
@ -23,10 +24,11 @@ public class TestAllMethods {
@Before @Before
public void before() { public void before() {
System.setProperty("com.sunyard.sydapi4j.debug", "false"); // 通过设置debug的属性开启debug如果不设置则默认不打开
// api = (SydApi4j) new SydApi4j().connect("172.16.17.163", 8889, null, 1000); System.setProperty("com.sunyard.sydapi4j.debug", "true");
api = (SydApi4j) new SydApi4j().connect("192.168.1.7", 8889, null, 5000); api = (SydApi4j) new SydApi4j().connect("192.168.0.100", 8889, null, 1000);
// api = (SydApi4j) new SydApi4j().connect("192.168.0.66", 8889, null, 1000); // api = (SydApi4j) new SydApi4j().connect("172.16.17.162", 8889, null, 1000);
// api = (SydApi4j) new SydApi4j().connect("192.168.1.7", 8889, null, 5000);
} }
@After @After
@ -671,6 +673,52 @@ public class TestAllMethods {
System.out.println(b); System.out.println(b);
} }
// 测试通过
// E0
@Test
public void testEncDecData() {
String msg = "1111111111111111111111";
/**
* 对称密钥产生
* @param keyType 密钥类型
* @param solution 密钥方案LMK 密钥长度/LMK下加密密钥的方案
* @return RetWrap 包含
* lmkKey LMK LMK加密密钥
* keyCheck 密钥校验值
*
*/
RetWrap retWrap = api.genSymmetricKey("000", 'X');
byte[] lmkKey = (byte[]) retWrap.get("lmkKey");
String key = new String(lmkKey);
/**
* 用输入的会话密钥对指定报文数据进行加密处理
*
* @param nAlg  算法标识.,0x00:3DES0x01:SM4
* @param seesionKey  本地LMK 加密的会话密钥HEX 格式
* @param pINdata  要加密的报文明文必须是 8 或16 的倍数
* @return 输出的报文密文, 长度为报文明文 + 16
*/
byte[] bytes = api.SYMEncryptDataCBC(1, key, msg.getBytes());
System.out.println("输出为: " + com.sunyard.proto.Util.bytes2HexString(bytes));
/**
* 用输入的会话密钥对指定报文数据进行解密处理
*
* @param nAlg  算法标识.,0x00:3DES0x01:SM4
* @param seesionKey 本地LMK 加密的会话密钥HEX 格式
* @param pINdata 要解密的报文密文长度必须是8 或16 的倍数
* @return 输出的报文明文
*/
byte[] bytes1 = api.SYMDecryptDataCBC(1, key, bytes);
System.out.println("明文:" + new String(bytes1));
}
@Test @Test
public void testaaa() throws UnsupportedEncodingException { public void testaaa() throws UnsupportedEncodingException {
String key = "X6CEE744329499B426CEE744329499B42"; String key = "X6CEE744329499B426CEE744329499B42";
@ -832,7 +880,7 @@ public class TestAllMethods {
// 81 // 81
@Test @Test
public void testSM2VerifyCustomized() { public void testSM2VerifyCustomized() {
String sn = "1004282452"; String sn = "1004282451";
String data = "111"; String data = "111";
String s = api.SM2SignCustomized(sn, data.getBytes()); String s = api.SM2SignCustomized(sn, data.getBytes());
@ -852,7 +900,7 @@ public class TestAllMethods {
// E2 // E2
@Test @Test
public void testSM2OrRSAGenKeyPair() { public void testSM2OrRSAGenKeyPair() {
String index = "1111111111111118"; String index = "1111111111111122";
// SM2 // SM2
RetWrap retWrap = api.SM2OrRSAGenKeyPair(1, index, 0); RetWrap retWrap = api.SM2OrRSAGenKeyPair(1, index, 0);
@ -1312,8 +1360,8 @@ public class TestAllMethods {
// 75 // 75
@Test @Test
public void testSM2Verify2() { public void testSM2Verify2() {
String privateKey = "00010000D7DBFD26A371D3B5BA58D3ECA98EAEFC1BCB65FA0DBBCFBC551E4315B8B2A8700000000000000000000000000000000000000000000000000000000000000000"; String privateKey = "AAA87526B2A261FF5468E489CF5E1E832BED34C31DCDA5D5093247FC20F6A8A7";
String thisPublicKey = "034200042E624577E3BF1A510804346D1054B9205D97B4579D6528C25CAE6B74E5CDD19774AFA17CD9017E6BCBD8D9F3903492CD5288932941583E113C804537B69CDD46"; String thisPublicKey = "C6084B3C227D6AD9201F36122418BDB13016678FC68D61E96F03C56702CFAE27B0190F48E9E9F05D3F550F18F1E6028B6B54F44A0272E16A9436F459A9D706BE";
String thisOrgData = "FFFFFFFFFFFFFFFF"; String thisOrgData = "FFFFFFFFFFFFFFFF";
String s = api.SM2SignC(0, privateKey, Util.hexString2Bytes(thisPublicKey), thisOrgData.getBytes()); String s = api.SM2SignC(0, privateKey, Util.hexString2Bytes(thisPublicKey), thisOrgData.getBytes());