sdf
This commit is contained in:
@@ -15,6 +15,8 @@ import com.sunyard.chsm.model.entity.Device;
|
||||
import com.sunyard.chsm.model.entity.ParamConf;
|
||||
import com.sunyard.chsm.model.entity.TmkInfo;
|
||||
import com.sunyard.chsm.sdf.adapter.BcSdfApiAdaptor;
|
||||
import com.sunyard.chsm.sdf.model.EccCipher;
|
||||
import com.sunyard.chsm.sdf.model.EccPubKey;
|
||||
import com.sunyard.chsm.service.DeviceService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.bouncycastle.util.encoders.Hex;
|
||||
@@ -209,15 +211,15 @@ public class DeviceServiceImpl implements DeviceService {
|
||||
BcSdfApiAdaptor sdfApi = new BcSdfApiAdaptor();
|
||||
byte[] sk = sdfApi.generateRandom("", 16);
|
||||
|
||||
byte[] publicKey = sdfApi.exportEncPublicKeyECC("", 1);
|
||||
byte[] encSk = sdfApi.externalEncryptECC("", publicKey, sk);
|
||||
EccPubKey publicKey = sdfApi.exportEncPublicKeyECC("", 1);
|
||||
EccCipher encSk = sdfApi.externalEncryptECC("", publicKey, sk);
|
||||
|
||||
TmkInfo info = new TmkInfo();
|
||||
info.setId(IdWorker.getId());
|
||||
info.setCreateTime(now);
|
||||
info.setDeviceSerial(sdfApi.getDeviceInfo("").getDeviceSerial());
|
||||
info.setEncTmk(Hex.toHexString(encSk));
|
||||
info.setPubKey(Hex.toHexString(publicKey));
|
||||
info.setEncTmk(Hex.toHexString(encSk.getC1C3C2Bytes()));
|
||||
info.setPubKey(Hex.toHexString(publicKey.getPubKeyBytes()));
|
||||
tmkInfoMapper.insert(info);
|
||||
// return;
|
||||
// }
|
||||
|
||||
@@ -7,10 +7,9 @@ import com.sunyard.chsm.mapper.SpDeviceMapper;
|
||||
import com.sunyard.chsm.model.entity.Device;
|
||||
import com.sunyard.chsm.sdf.adapter.SdfApiAdapter;
|
||||
import com.sunyard.chsm.sdf.adapter.SdfApiAdapterFactory;
|
||||
import com.sunyard.chsm.sdf.context.DeviceContext;
|
||||
import com.sunyard.chsm.sdf.model.DeviceInfo;
|
||||
import com.sunyard.chsm.sdf.model.EccPubKey;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.bouncycastle.util.encoders.Hex;
|
||||
import org.springframework.beans.factory.InitializingBean;
|
||||
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
|
||||
import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler;
|
||||
@@ -52,20 +51,15 @@ public class DeviceTask implements InitializingBean {
|
||||
}
|
||||
|
||||
for (Device record : records) {
|
||||
DeviceContext context = new DeviceContext();
|
||||
context.setServiceIp(record.getServiceIp());
|
||||
context.setServicePort(record.getServicePort());
|
||||
context.setManufacturer(record.getManufacturer());
|
||||
context.setManufacturerModel(record.getManufacturerModel());
|
||||
boolean connected = false;
|
||||
try {
|
||||
SdfApiAdapter sdfApiAdapter = SdfApiAdapterFactory.newInstance(context);
|
||||
SdfApiAdapter sdfApiAdapter = SdfApiAdapterFactory.newInstance(record.getManufacturerModel(), record.getServiceIp(), record.getServicePort());
|
||||
String dh = sdfApiAdapter.openDevice();
|
||||
String sh = sdfApiAdapter.openSession(dh);
|
||||
DeviceInfo info = sdfApiAdapter.getDeviceInfo(sh);
|
||||
log.info("get DeviceInfo: {}", info);
|
||||
byte[] eccPubKey = sdfApiAdapter.exportEncPublicKeyECC(sh, 2);
|
||||
log.info("exportEncPublicKeyECC: {}", Hex.toHexString(eccPubKey));
|
||||
EccPubKey eccPubKey = sdfApiAdapter.exportEncPublicKeyECC(sh, 2);
|
||||
log.info("exportEncPublicKeyECC: {}", eccPubKey.getPubKeyHex());
|
||||
sdfApiAdapter.closeSession(sh);
|
||||
sdfApiAdapter.closeDevice(dh);
|
||||
connected = true;
|
||||
|
||||
Reference in New Issue
Block a user