答:

data要加密的数据,key密钥

public static String HMACSHA256(String data, String key) throws Exception {

       Mac sha256_HMAC = Mac.getInstance("HmacSHA256");

       SecretKeySpec secret_key = new SecretKeySpec(key.getBytes("UTF-8"), "HmacSHA256");

       sha256_HMAC.init(secret_key);

       byte[] array = sha256_HMAC.doFinal(data.getBytes("UTF-8"));

       StringBuilder sb = new StringBuilder();

       for (byte item : array) {

           sb.append(Integer.toHexString((item & 0xFF) | 0x100).substring(1, 3));

       }

       return sb.toString().toUpperCase();

   }

相关文章:

  • 2022-12-23
  • 2021-11-06
  • 2022-01-05
  • 2021-12-20
  • 2021-12-28
  • 2021-10-04
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-06-29
  • 2022-12-23
  • 2021-05-24
  • 2021-09-12
  • 2021-12-11
  • 2022-12-23
相关资源
相似解决方案