HMACSHA256加密

  public static String HMACSHA256(final String strText, final String strKey) {
        String strResult = null;
        try {
            Mac           sha256_HMAC = Mac.getInstance("HmacSHA256");
            SecretKeySpec secretKey   = new SecretKeySpec(strKey.getBytes(), "HmacSHA256");
            sha256_HMAC.init(secretKey);
            byte[] hash = sha256_HMAC.doFinal(strText.getBytes());
            //strResult = new String(Hex.encodeHex(hash));
           // strResult = byte2hex(hash);
            strResult = toHexString(hash);
            return strResult;
        } catch (NoSuchAlgorithmException e) {
            return strResult;
        } catch (InvalidKeyException e) {
            return strResult;
        }
    }
 private static String toHexString(byte[]b){
        StringBuilder hs = new StringBuilder();
        String stmp;
        for(int n = 0;b!=null&&n

 

你可能感兴趣的:(整理)