添加SK指令生成随机数接口

This commit is contained in:
zhoubin 2021-08-22 11:44:35 +08:00
parent 934aa52338
commit a9289bd0d1
4 changed files with 92 additions and 0 deletions

51
DProto/SK.xml Normal file
View File

@ -0,0 +1,51 @@
<?xml version="1.0" encoding="UTF-8" ?>
<packet extend="base">
<req>
<command>
<hex>SK</hex>
</command>
<data extend = "data">
<nRandomSize len="4" cn="产生随机数长度">
需要产生的随机数长度
注意: 最大不超过4K
</nRandomSize>
</data>
</req>
<res>
<command>
<hex>SL</hex>
</command>
<data>
<error len="2" cn="错误码" format="X" :catch="catchError('%s')">
<options>
<option cn="无错误">
<hex>00</hex>
</option>
<option cn="无效的哈希标识">
<hex>05</hex>
</option>
<option cn="输入数据有误">
<hex>15</hex>
</option>
<option cn="DSP:错误,报告给管理员">
<hex>47</hex>
</option>
<option cn="数据长度错误">
<hex>80</hex>
</option>
</options>
</error>
<random maxLen="255" :len="getRandomSize()" cn="产生的随机数"></random>
</data>
</res>
<script>function getRandomSize(){
var data = $packet.data;
return data.nRandomSize;
}
</script>
</packet>

Binary file not shown.

View File

@ -255,4 +255,10 @@ public interface SydZYOption {
byte[] decryptByMainAndSYMEn(String encryptKeyIndex, int encryptAlgFlag, byte[] encryptIv, int encryptKeyDivNum,
List<byte[]> encryptKeyDivData, int[] encryptKeyDivAlgFlag, List<byte[]> encryptKeyDivIv, byte[] inputData);
/**
* 产生随机数
* @param nRandomSize 产生随机数长度
* @return 随机数
*/
String GenRandom(int nRandomSize);
}

View File

@ -9932,5 +9932,40 @@ public class SydApi4j implements SydApi {
}
}
@Override
public String GenRandom(int nRandomSize) {
//获取协议
ProtoSK proto = new ProtoSK();
//填充数据
PacketSN sn = PacketSN.gen();
HashMap<String, Object> packet = new HashMap<String, Object>();
packet.put("header", sn.getSn().array());
HashMap<String, Object> data = new HashMap<String, Object>();
data.put("nRandomSize", nRandomSize);
packet.put("data", data);
//渲染发送
ByteBuffer bb = proto.rend(packet);
synchronized (this) {
//解析响应
bb = syncRead(syncSend(bb));
}
Packet p = proto.parse(bb, packet);
Map<String, Object> ret = p.toMap();
if (
!Arrays.equals(sn.getSn().array(), ((PacketSection) ret.get("header")).getBytes())
) {
throw new SydApiException("包序号不匹配", -4);
}
ret = (Map<String, Object>) ret.get("data");
PacketSection error = (PacketSection) ret.get("error");
if (!"00".equals(error.getString())) {
throw new SydApiException(error.getInfo(), error.autoInt());
}
return Util.bytes2HexString(((PacketSection) ret.get("random")).getBytes());
}
// ---------------------中移指令结束--------------------------------
}