use of com.bsnbase.sdk.util.enums.AlgorithmTypeEnum in project PCNGateway-Java-SDK by BSNDA.
the class BaseResArrayModel method verify.
@Override
public boolean verify() throws Exception {
String signValue = (this.header == null ? "" : this.header.getHeaderString());
for (int i = 0; i < this.body.size(); i++) {
signValue += this.body.get(i).getEncryptionValue();
}
AlgorithmTypeEnum algorithmTypeEnum = AlgorithmTypeEnum.fromAlgorithmTypeEnum(Config.config.getAppInfo().getAlgorithmType());
AlgorithmTypeContext algorithmTypeContext = new AlgorithmTypeContext(algorithmTypeEnum);
boolean verify = algorithmTypeContext.getAlgorithmTypeHandle().verify(PublicConfig.getPublicKey(algorithmTypeEnum), this.mac, signValue);
return verify;
}
use of com.bsnbase.sdk.util.enums.AlgorithmTypeEnum in project PCNGateway-Java-SDK by BSNDA.
the class BaseResModel method verify.
/**
* Gateway returns the result of signature verfication
*/
@Override
public boolean verify() throws Exception {
String signValue = (this.header == null ? "" : this.header.getHeaderString()) + (this.body == null ? "" : this.body.getEncryptionValue());
AlgorithmTypeEnum algorithmTypeEnum = AlgorithmTypeEnum.fromAlgorithmTypeEnum(Config.config.getAppInfo().getAlgorithmType());
AlgorithmTypeContext algorithmTypeContext = new AlgorithmTypeContext(algorithmTypeEnum);
boolean verify = algorithmTypeContext.getAlgorithmTypeHandle().verify(PublicConfig.getPublicKey(algorithmTypeEnum), this.mac, signValue);
return verify;
}
use of com.bsnbase.sdk.util.enums.AlgorithmTypeEnum in project PCNGateway-Java-SDK by BSNDA.
the class TransactionService method nodeTrans.
/**
* Invoke chaincode in Public Key Upload Mode
* <p>
* When the user of the public key upload mode application needs to initiate a transaction from the off-chain system to the chaincode on the chain, he/she needs to assemble the transaction message locally and call this interface to initiate the transaction.
*/
public static ResKeyEscrowNo nodeTrans(@NotNull ReqKeyEscrow reqkey) throws NoSuchAlgorithmException {
String api = Config.config.getApi() + PathUtil.FABRIC_NODE_TRANS;
TransactionUser user = null;
try {
user = Config.config.getKeyStore().loadUser(reqkey.getUserName(), Config.config.getAppCode());
user.setMspId(Config.config.getAppInfo().getMspId());
AlgorithmTypeEnum algorithmTypeEnum = AlgorithmTypeEnum.fromAlgorithmTypeEnum(Config.config.getAppInfo().getAlgorithmType());
if (algorithmTypeEnum == AlgorithmTypeEnum.AppAlgorithmType_SM2 && Config.config.getAppInfo().getFabricVersion().equals("2.2.1")) {
user.setSM3(true);
}
} catch (IOException e) {
e.printStackTrace();
throw new GlobalException(ResultInfoEnum.USER_CERTIFICATE_ERROR.getMsg());
}
// Assemble the transaction information
TransactionRequest request = new TransactionRequest();
request.setChannelId(Config.config.getAppInfo().getChannelId());
request.setArgs(Common.StringBytesConvert(reqkey.getArgs()));
request.setTransientMap(reqkey.getTransientData());
request.setChaincodeId(reqkey.getChainCode());
request.setFcn(reqkey.getFuncName());
String transData = null;
try {
transData = getTransdata(request, user);
} catch (Exception e) {
e.printStackTrace();
throw new GlobalException(ResultInfoEnum.TRANSACTION_CONVERSION_ERROR.getMsg());
}
ReqKeyEscrowNo keyNo = new ReqKeyEscrowNo();
keyNo.setTransData(transData);
BaseReqModel<ReqKeyEscrowNo> req = new BaseReqModel<ReqKeyEscrowNo>();
req.setReqHeader(Config.config.getUserCode(), Config.config.getAppCode());
req.setBody(keyNo);
HttpService<ReqKeyEscrowNo, ResKeyEscrowNo> httpService = new HttpService<ReqKeyEscrowNo, ResKeyEscrowNo>();
BaseResModel<ResKeyEscrowNo> res = httpService.post(req, api, ResKeyEscrowNo.class);
return res.getBody();
}
use of com.bsnbase.sdk.util.enums.AlgorithmTypeEnum in project PCNGateway-Java-SDK by BSNDA.
the class FiscoTransUtil method getEncryptTypeByAlgorithmType.
private static EncryptType getEncryptTypeByAlgorithmType(Integer algorithmType) {
EncryptType encryptType = null;
AlgorithmTypeEnum algorithmTypeEnum = AlgorithmTypeEnum.fromAlgorithmTypeEnum(algorithmType);
switch(algorithmTypeEnum) {
case AppAlgorithmType_SM2:
encryptType = new EncryptType(1);
break;
case AppAlgorithmType_K1:
encryptType = new EncryptType(0);
break;
default:
}
if (Objects.isNull(encryptType)) {
throw new GlobalException(ResultInfoEnum.ALGORITHM_TYPE_ERROR);
}
return encryptType;
}
use of com.bsnbase.sdk.util.enums.AlgorithmTypeEnum in project PCNGateway-Java-SDK by BSNDA.
the class StoreUtils method generateCSR.
/**
* csr generation
*
* @param name
* @param appCode
* @return
*/
public static UserCertInfo generateCSR(String name, String appCode) {
try {
String DN = "CN=" + Common.getCNName(name, appCode) + ",OU=client";
AlgorithmTypeEnum algorithmTypeEnum = AlgorithmTypeEnum.fromAlgorithmTypeEnum(Config.config.getAppInfo().getAlgorithmType());
AlgorithmTypeContext algorithmTypeContext = new AlgorithmTypeContext(algorithmTypeEnum);
UserCertInfo certInfo = algorithmTypeContext.getAlgorithmTypeHandle().getUserCertInfo(DN);
if (Objects.isNull(certInfo)) {
throw new GlobalException(ResultInfoEnum.ALGORITHM_TYPE_ERROR);
}
return certInfo;
} catch (Exception e) {
logger.error("Get CSR Exception", e);
throw new GlobalException("Get CSR Exception");
}
}
Aggregations