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;
    }
    听说学习能够让青春永驻。
  • 相关阅读:
    2020/4/15
    2020/4/14
    2020/4/13
    2020/4/12
    2020/4/11
    2020/4/9
    PTA录入数据库题目流程
    PTA录题
    2020/4/8
    如何把mysql workbench的数据结构和数据导出到sql表中
  • 原文地址:https://www.cnblogs.com/chenyf/p/8494542.html
Copyright © 2011-2022 走看看