This is sharedConfig class: package com.sc.we.idv.config; import…
- User
This is sharedConfig class: package com.sc.we.idv.config;
import org.springframework.stereotype.Component;
@Component public class SharedConfig { private boolean shouldStubInitialize; private boolean ShouldStubGetDemographics;
public boolean isShouldStubInitialize() { return shouldStubInitialize; } public void setShouldStubInitialize(boolean shouldStubInitialize) { this.shouldStubInitialize = shouldStubInitialize; } public boolean isShouldStubGetDemographics() { return ShouldStubGetDemographics; } public void setShouldStubGetDemographics(boolean shouldStubGetDemographics) { ShouldStubGetDemographics = shouldStubGetDemographics; }}
This is ZolozEncryptAndGenSignService class: package com.sc.we.idv.plugin.client.zoloz;
import java.io.IOException; import java.time.ZonedDateTime; import java.time.format.DateTimeFormatter;
import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Service;
import com.sc.we.idv.common.constants.IDVConstants; import com.sc.we.idv.config.SharedConfig; import com.sc.we.idv.plugin.client.zoloz.model.EncryptRequestDTO; import com.sc.we.idv.plugin.client.zoloz.util.AESUtil; import com.sc.we.idv.plugin.client.zoloz.util.GenSignUtil; import com.sc.we.idv.plugin.client.zoloz.util.KeyUtil; import com.sc.we.idv.plugin.client.zoloz.util.RSAUtil;
@Service public class ZolozEncryptAndGenSignService {
@Value("${zoloz.client.id}") private String clientId; @Value("${zoloz.merchant.privkey.path}") private String merchantPrivKeyPath; @Value("${zoloz.pubkey}") private String openApiPublicKey; private static final Logger logger = LoggerFactory.getLogger(ZolozEncryptAndGenSignService.class); @Value("${live.endpoint}") private boolean signed; @Value("${live.endpoint}") private boolean encrypted; @Autowired private SharedConfig sharedConfig; public EncryptRequestDTO encryptService(String request, String apiName) { String encryptKey = null; byte[] key = null; String encryptedRequest = null; encrypted = (apiName.equals(IDVConstants.GET_INITIALIZE_ZOLOZ_ENDPOINT)) ? (sharedConfig.isShouldStubInitialize() ? false : true) : (apiName.equals(IDVConstants.GET_DEMOGRAPHIC_ZOLOZ_ENDPOINT) ? (sharedConfig.isShouldStubGetDemographics() ? false : true) : encrypted); try { if (encrypted) { key = AESUtil.generateKey(128); encryptedRequest = AESUtil.encrypt(key, request); encryptKey = RSAUtil.encrypt(openApiPublicKey, key); } else { encryptedRequest = request; } } catch (Exception e) { logger.info("ENCRYPTION ERROR" + e.getMessage()); } EncryptRequestDTO encryptRequestDTO = new EncryptRequestDTO(); encryptRequestDTO.setKey(key); encryptRequestDTO.setEncryptedRequest(encryptedRequest); encryptRequestDTO.setEncryptedkey(encryptKey); return encryptRequestDTO; } public EncryptRequestDTO generateSignature(EncryptRequestDTO encryptRequestDTO,String apiName) throws Exception{ String reqTime = ZonedDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ssZ")); String signature = null; signed = (apiName.equals(IDVConstants.GET_INITIALIZE_ZOLOZ_ENDPOINT)) ? (sharedConfig.isShouldStubInitialize() ? false : true) : (apiName.equals(IDVConstants.GET_DEMOGRAPHIC_ZOLOZ_ENDPOINT) ? (sharedConfig.isShouldStubGetDemographics() ? false : true) : signed); if (signed) { signature = sign(loadPrivateKeyFromFile(merchantPrivKeyPath), apiName, clientId, reqTime, encryptRequestDTO.getEncryptedRequest()); } logger.info("signature generated"+signature); encryptRequestDTO.setSignature(signature); encryptRequestDTO.setReqTime(reqTime); return encryptRequestDTO; } protected String sign(String merchantPrivateKey, String api, String clientId, String reqTime, String request) throws Exception { StringBuffer sb = new StringBuffer(request.length() + 256); sb.append("POST ").append("/api/").append(api.replaceAll("\\.", "/")).append("\n"); sb.append(clientId).append(".").append(reqTime).append(".").append(request); String str = sb.toString(); return GenSignUtil.sign(merchantPrivateKey, str); } private String loadPrivateKeyFromFile(String merchantPrivKeyPath) { String merchantPrivateKey = null; try { merchantPrivateKey = KeyUtil.loadKeyContentFromPath(merchantPrivKeyPath); logger.info("======== private ket loaded from file classpath ========"); } catch (IOException e) { logger.debug("XXXXXXXXXXXXXXXXERROR LOADING PRIVATE KEYXXXXXXXXXXXXXXXXXXXXX"); } return merchantPrivateKey; } - Assistant
- User
- Assistant