Search in sources :

Example 1 with AlgorithmTypeContext

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

Example 2 with AlgorithmTypeContext

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

Example 3 with AlgorithmTypeContext

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

Example 4 with AlgorithmTypeContext

use of com.bsnbase.sdk.util.algorithm.AlgorithmTypeContext 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

AlgorithmTypeContext (com.bsnbase.sdk.util.algorithm.AlgorithmTypeContext)4 AlgorithmTypeEnum (com.bsnbase.sdk.util.enums.AlgorithmTypeEnum)4 GlobalException (com.bsnbase.sdk.util.exception.GlobalException)2