All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.gitee.easyopen.ApiSigner Maven / Gradle / Ivy

Go to download

easyopen mini版,保留基本签名校验,文档功能。https://gitee.com/durcframework/easyopen

There is a newer version: 1.0.4
Show newest version
package com.gitee.easyopen;

import java.util.HashMap;
import java.util.Map;

import com.gitee.easyopen.message.Errors;
import com.gitee.easyopen.verify.DefaultMd5Verifier;
import com.gitee.easyopen.verify.Verifier;

/**
 * 签名验证实现
 * @author tanghc
 *
 */
public class ApiSigner implements Signer {
    
    private Map checker = new HashMap<>();
    
    public ApiSigner() {
        checker.put("md5", new DefaultMd5Verifier());
    }
    
    /**
     * 添加签名检查器
     * @param algorithmName
     * @param checker
     */
    public void addChecker(String algorithmName,Verifier checker) {
        this.checker.put(algorithmName, checker);
    }

    @Override
    public boolean isRightSign(ApiParam apiParam, String secret,String signMethod) {
        Verifier verifier = checker.get(signMethod.toLowerCase());
        if(verifier == null) {
            throw Errors.ERROR_ALGORITHM.getException(signMethod);
        }
        return verifier.verify(apiParam, secret);
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy