use of com.bsnbase.sdk.util.enums.AlgorithmTypeEnum in project PCNGateway-Java-SDK by BSNDA.
the class TransData method getTransdata.
public static String getTransdata(TransactionRequest request, TransactionUser user) throws Exception {
ProposalPackage.Proposal proposal = proposal(request, user);
byte[] proposalBytes = convertToBytes(proposal);
byte[] signBytes;
try {
AlgorithmTypeEnum algorithmTypeEnum = AlgorithmTypeEnum.fromAlgorithmTypeEnum(com.bsnbase.sdk.entity.config.Config.config.getAppInfo().getAlgorithmType());
signBytes = FabricTransUtil.getTransSign(algorithmTypeEnum, user.getPrivateKey(), proposalBytes);
} catch (Exception e) {
throw new GlobalException(ResultInfoEnum.TRANSACTION_SIGNING_ERROR);
}
ProposalPackage.SignedProposal.Builder sig = ProposalPackage.SignedProposal.newBuilder();
sig.setProposalBytes(getByteString(proposalBytes));
sig.setSignature(getByteString(signBytes));
byte[] signProposalBytes = convertToBytes(sig.build());
return Base64.getEncoder().encodeToString(signProposalBytes);
}
use of com.bsnbase.sdk.util.enums.AlgorithmTypeEnum in project PCNGateway-Java-SDK by BSNDA.
the class BaseReqModel method sign.
/**
* The request gateway calls the "sign" method
*/
@Override
public void sign() throws Exception {
if (this.header == null) {
throw new GlobalException(ResultInfoEnum.REQUEST_HEADER_ERROR);
}
String signValue = this.header.getHeaderString();
if (this.body != null) {
signValue += this.body.getEncryptionValue();
}
AlgorithmTypeEnum algorithmTypeEnum = AlgorithmTypeEnum.fromAlgorithmTypeEnum(Config.config.getAppInfo().getAlgorithmType());
AlgorithmTypeContext algorithmTypeContext = new AlgorithmTypeContext(algorithmTypeEnum);
String sign = algorithmTypeContext.getAlgorithmTypeHandle().sign(Config.config.getPrk(), signValue);
this.mac = sign;
}
Aggregations