Search in sources :

Example 6 with AlgorithmTypeEnum

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);
}
Also used : AlgorithmTypeEnum(com.bsnbase.sdk.util.enums.AlgorithmTypeEnum) ProposalPackage(org.hyperledger.fabric.protos.peer.ProposalPackage) IOException(java.io.IOException) GlobalException(com.bsnbase.sdk.util.exception.GlobalException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) GlobalException(com.bsnbase.sdk.util.exception.GlobalException)

Example 7 with AlgorithmTypeEnum

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;
}
Also used : AlgorithmTypeEnum(com.bsnbase.sdk.util.enums.AlgorithmTypeEnum) AlgorithmTypeContext(com.bsnbase.sdk.util.algorithm.AlgorithmTypeContext) GlobalException(com.bsnbase.sdk.util.exception.GlobalException)

Aggregations

AlgorithmTypeEnum (com.bsnbase.sdk.util.enums.AlgorithmTypeEnum)7 GlobalException (com.bsnbase.sdk.util.exception.GlobalException)5 AlgorithmTypeContext (com.bsnbase.sdk.util.algorithm.AlgorithmTypeContext)4 IOException (java.io.IOException)2 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)2 BaseReqModel (com.bsnbase.sdk.entity.base.BaseReqModel)1 ReqKeyEscrowNo (com.bsnbase.sdk.entity.req.fabric.ReqKeyEscrowNo)1 ResKeyEscrowNo (com.bsnbase.sdk.entity.resp.fabric.ResKeyEscrowNo)1 TransactionRequest (com.bsnbase.sdk.entity.transactionHeader.TransactionRequest)1 TransactionUser (com.bsnbase.sdk.entity.transactionHeader.TransactionUser)1 HttpService (com.bsnbase.sdk.util.common.HttpService)1 EncryptType (org.fisco.bcos.web3j.crypto.EncryptType)1 ProposalPackage (org.hyperledger.fabric.protos.peer.ProposalPackage)1