添加SK指令生成随机数接口
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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());
|
||||
}
|
||||
|
||||
// ---------------------中移指令结束--------------------------------
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user