添加中移指令接口

This commit is contained in:
zhoubin
2021-08-12 10:47:32 +08:00
parent 45f81f4685
commit a1c66f685c
26 changed files with 4590 additions and 17 deletions
@@ -0,0 +1,144 @@
package com.sunyard.entity;
import com.sunyard.util.MyUtil;
import java.nio.ByteBuffer;
import java.util.List;
/**
* @Auther: wp
* @Date: 2021/6/1 20:11
* @Description:
*/
//导出密钥分散结构体
public class Struct {
String ucKeyIdex; //导出密钥索引
int iKeyDivNum; //导出密钥分散级数
List<byte[]> ucKeyDivData; //导出密钥分散数据
int[] iKeyDivAlg; //导出密钥分散算法
List<byte[]> ucKeyDivIv; //导出密钥IV
int iCheckValueType; //导出密钥校验值生成类型
public int getiCheckValueType() {
return iCheckValueType;
}
public void setiCheckValueType(int iCheckValueType) {
this.iCheckValueType = iCheckValueType;
}
public Struct() {
}
public Struct(String ucKeyIdex, int iKeyDivNum, List<byte[]> ucKeyDivData, int[] iKeyDivAlg, List<byte[]> ucKeyDivIv, int iCheckValueType) {
this.setUcKeyIdex(ucKeyIdex);
this.iKeyDivNum = iKeyDivNum;
this.setUcKeyDivData(ucKeyDivData);
this.iKeyDivAlg = iKeyDivAlg;
this.setUcKeyDivIv(ucKeyDivIv);
this.iCheckValueType=iCheckValueType;
}
public String getUcKeyIdex() {
return ucKeyIdex;
}
public void setUcKeyIdex(String ucKeyIdex) {
String gId = "00000000" + ucKeyIdex;
gId = gId.substring(gId.length() - 8);
ucKeyIdex="0000000000000000000"+gId;
// byte[] b= new byte[27];
// System.arraycopy(ucKeyIdex,0,b,0,ucKeyIdex.length);
this.ucKeyIdex = ucKeyIdex;
}
public int getiKeyDivNum() {
return iKeyDivNum;
}
public void setiKeyDivNum(int iKeyDivNum) {
this.iKeyDivNum = iKeyDivNum;
}
public List<byte[]> getUcKeyDivData() {
return ucKeyDivData;
}
public void setUcKeyDivData(List<byte[]> ucKeyDivData) {
// byte[] b= new byte[48];
// System.arraycopy(ucKeyDivData,0,b,0,ucKeyDivData.length);
this.ucKeyDivData = ucKeyDivData;
}
public List<byte[]> getUcKeyDivIv() {
return ucKeyDivIv;
}
public void setUcKeyDivIv(List<byte[]> ucKeyDivIv) {
this.ucKeyDivIv = ucKeyDivIv;
}
public int[] getiKeyDivAlg() {
return iKeyDivAlg;
}
public void setiKeyDivAlg(int[] iKeyDivAlg) {
this.iKeyDivAlg = iKeyDivAlg;
}
public byte[] getByte() {
ByteBuffer byteBuffer = ByteBuffer.allocate(144);
//导出密钥索引
byteBuffer.put(ucKeyIdex.getBytes());
byteBuffer.put((byte) 0x0);
//分散级数,补充到4字节
byte[] bytes = MyUtil.int2ReverseByteArray(iKeyDivNum);
byte[] b1= new byte[4];
System.arraycopy(bytes,0,b1,0,bytes.length);
byteBuffer.put(b1);
//导出密钥分散数据
byte[] byteData= new byte[48];
int destPos=0;
for (byte[] b:ucKeyDivData ){
System.arraycopy(b,0,byteData,destPos,b.length);
destPos+=b.length;
}
byteBuffer.put(byteData);
//填充分散算法,每一个补充到4字节
for (int i = 0; i < 3; i++) {
byte[] bytes1;
if(i<iKeyDivAlg.length){
bytes1 = MyUtil.int2ReverseByteArray(MyUtil.transAlg(iKeyDivAlg[i]));
}else{
bytes1=new byte[4];
}
byte[] b2= new byte[4];
System.arraycopy(bytes1,0,b2,0,bytes1.length);
byteBuffer.put(b2);
}
//导出密钥IV
byte[] byteIv= new byte[48];
int destIvPos=0;
for (byte[] b:ucKeyDivIv ){
System.arraycopy(b,0,byteIv,destIvPos,b.length);
destPos+=b.length;
}
byteBuffer.put(byteIv);
//密钥校验值生成类型,补充到4字节
byte[] bytes1 = MyUtil.int2ReverseByteArray(iCheckValueType);
byte[] b2= new byte[4];
System.arraycopy(bytes1,0,b2,0,bytes1.length);
byteBuffer.put(b2);
return MyUtil.bytebuffer2ByteArray(byteBuffer);
}
}