<NME> SignUtils.java
<BEF> package com.egzosn.pay.common.util.sign;


import com.egzosn.pay.common.util.str.StringUtils;
import org.apache.http.message.BasicNameValuePair;

import java.util.*;

/**
 * @author egan
 * <pre>
 * email egzosn@gmail.com
 * date 2016/11/9 17:45
 * </pre>
 */
public enum SignUtils implements SignType {

    MD5 {
        /**
         *
         * @param content           需要签名的内容
         * @param key               密钥
         * @param characterEncoding 字符编码
         * @return 签名值
         */
        @Override
        public String createSign(String content, String key, String characterEncoding) {

            return com.egzosn.pay.common.util.sign.encrypt.MD5.sign(content, key, characterEncoding);
        }

        /**
         * 签名字符串
         * @param text 需要签名的字符串
         * @param sign 签名结果
         * @param key 密钥
         * @param characterEncoding 编码格式
         * @return 签名结果
         */
        @Override
        public boolean verify(String text, String sign, String key, String characterEncoding) {
            return com.egzosn.pay.common.util.sign.encrypt.MD5.verify(text, sign, key, characterEncoding);
        public boolean verify(String text, String sign, String key, String characterEncoding) {
            return com.egzosn.pay.common.util.sign.encrypt.MD5.verify(text, sign, key, characterEncoding);
        }
    },

    RSA {

        @Override
        public boolean verify(String text, String sign, String publicKey, String characterEncoding) {
            return com.egzosn.pay.common.util.sign.encrypt.RSA2.verify(text, sign, publicKey, characterEncoding);
        }
    },
    SHA1 {
        @Override
        public String createSign(String content, String key, String characterEncoding) {
            return com.egzosn.pay.common.util.sign.encrypt.SHA1.sign(content, key, characterEncoding);
        }

        @Override
        public boolean verify(String text, String sign, String publicKey, String characterEncoding) {
            return com.egzosn.pay.common.util.sign.encrypt.SHA1.verify(text, sign, publicKey, characterEncoding);
        }
    },
    SHA256 {
        @Override
        public String createSign(String content, String key, String characterEncoding) {
            return com.egzosn.pay.common.util.sign.encrypt.SHA256.sign(content, key, characterEncoding);
        }

        @Override
        public boolean verify(String text, String sign, String publicKey, String characterEncoding) {
            return com.egzosn.pay.common.util.sign.encrypt.SHA256.verify(text, sign, publicKey, characterEncoding);
        }
    },
    SM3 {
        @Override
        public String createSign(String content, String key, String characterEncoding) {
            return com.egzosn.pay.common.util.sign.encrypt.RSA2.sign(content, key, characterEncoding);
        }

        @Override
        public boolean verify(String text, String sign, String publicKey, String characterEncoding) {
            return com.egzosn.pay.common.util.sign.encrypt.RSA2.verify(text, sign, publicKey, characterEncoding);
        }
    };



    @Override
    public String getName() {
        return this.name();
    }

    /**
     * 签名
     *
     * @param parameters        需要进行排序签名的参数
     * @param key               密钥
     * @param characterEncoding 编码格式
     * @return 签名值
     */
    public String sign(Map parameters, String key, String characterEncoding) {

        return createSign(parameterText(parameters, "&"), key, characterEncoding);
    }

    /**
     * 签名
     *
     * @param parameters        需要进行排序签名的参数
     * @param key               密钥
     * @param separator         分隔符  默认 &amp;
     * @param characterEncoding 编码格式
     * @return 签名值
     */
    public String sign(Map parameters, String key, String separator, String characterEncoding) {

        return createSign(parameterText(parameters, separator), key, characterEncoding);

    }


    /**
     * 签名字符串
     *
     * @param params            需要签名的字符串
     * @param sign              签名结果
     * @param key               密钥
     * @param characterEncoding 编码格式
     * @return 签名结果
     */
    public boolean verify(Map params, String sign, String key, String characterEncoding) {
        //判断是否一样
        return this.verify(parameterText(params), sign, key, characterEncoding);
    }

    /**
     * 初始化BC
     */
    public static void initBc() {
        if (null == Security.getProvider("BC")) {
            Security.removeProvider("SunEC");
            Security.addProvider(new BouncyCastleProvider());
        }
    }


}

<MSG> 转账定义，银行定义，签名类型增加HMAC-SHA256

<DFF> @@ -1,9 +1,16 @@
 package com.egzosn.pay.common.util.sign;
 
 
+import com.egzosn.pay.common.bean.result.PayException;
+import com.egzosn.pay.common.exception.PayErrorException;
 import com.egzosn.pay.common.util.str.StringUtils;
 import org.apache.http.message.BasicNameValuePair;
 
+import javax.crypto.Mac;
+import javax.crypto.spec.SecretKeySpec;
+import java.io.UnsupportedEncodingException;
+import java.security.InvalidKeyException;
+import java.security.NoSuchAlgorithmException;
 import java.util.*;
 
 /**
@@ -43,6 +50,54 @@ public enum SignUtils {
         public boolean verify(String text, String sign, String key, String characterEncoding) {
             return com.egzosn.pay.common.util.sign.encrypt.MD5.verify(text, sign, key, characterEncoding);
         }
+    },HMACSHA256{
+        /**
+         * 签名
+         *
+         * @param content           需要签名的内容
+         * @param key               密钥
+         * @param characterEncoding 字符编码
+         *
+         * @return 签名值
+         */
+        @Override
+        public String createSign(String content, String key, String characterEncoding) {
+            Mac sha256_HMAC = null;
+            try {
+                sha256_HMAC = Mac.getInstance("HmacSHA256");
+                SecretKeySpec secret_key = new SecretKeySpec(key.getBytes(characterEncoding), "HmacSHA256");
+                sha256_HMAC.init(secret_key);
+                byte[] array = sha256_HMAC.doFinal(content.getBytes(characterEncoding));
+                StringBuilder sb = new StringBuilder();
+                for (byte item : array) {
+                    sb.append(Integer.toHexString((item & 0xFF) | 0x100).substring(1, 3));
+                }
+                return sb.toString().toUpperCase();
+            } catch (NoSuchAlgorithmException e) {
+                e.printStackTrace();
+            } catch (InvalidKeyException e) {
+                e.printStackTrace();
+            } catch (UnsupportedEncodingException e) {
+                e.printStackTrace();
+            }
+
+            throw new PayErrorException(new PayException("fail", "HMACSHA256 签名异常"));
+        }
+
+        /**
+         * 签名字符串
+         *
+         * @param text              需要签名的字符串
+         * @param sign              签名结果
+         * @param key               密钥
+         * @param characterEncoding 编码格式
+         *
+         * @return 签名结果
+         */
+        @Override
+        public boolean verify(String text, String sign, String key, String characterEncoding) {
+            return createSign(text, key, characterEncoding).equals(sign);
+        }
     },
 
     RSA {

转账定义，银行定义，签名类型增加HMAC-SHA256