zoukankan      html  css  js  c++  java
  • HmacSHA256签名加Base64编码加URL编码

    /**
    *先使用HmacSHA256签名,再使用Base64编码,最后进行URL 编码
    *signatureReqStr : 待加密data
    * secretKey : 密钥
    */
    public static String getSignature(String signatureReqStr,String secretKey){
    Mac sha256_HMAC ;
    String result = "";
    try {
    sha256_HMAC = Mac.getInstance("HmacSHA256");
    SecretKeySpec secret_key = new SecretKeySpec(secretKey.getBytes(), "HmacSHA256");
    sha256_HMAC.init(secret_key);
    result = Base64.encodeBase64String(sha256_HMAC.doFinal(signatureReqStr.getBytes()));
    result = URLEncoder.encode(result);
    } catch (InvalidKeyException e) {
    e.printStackTrace();
    } catch (NoSuchAlgorithmException e) {
    e.printStackTrace();
    }
    return result;
    }
    听说学习能够让青春永驻。
  • 相关阅读:
    4-11
    4-10
    4-9
    4-7
    4-8
    4-6
    4-4
    4-5
    4-3
    4-2
  • 原文地址:https://www.cnblogs.com/chenyf/p/8494542.html
Copyright © 2011-2022 走看看