HmacSha1Utils { public static String signString(String stringToSign, String accessKeySecret) { try { Mac mac = Mac.getInstance(ALGORITHM_NAME); mac.init(new SecretKeySpec( accessKeySecret.getBytes(ENCODING), ALGORITHM_NAME )); byte[] signData = mac.doFinal(stringToSign.getBytes(ENCODING)); return BaseEncoding.base64().encode(signData); } catch (NoSuchAlgorithmException | UnsupportedEncodingException | InvalidKeyException e) { throw new IllegalArgumentException(e.toString()); } }  static String signString(String stringToSign, String accessKeySecret);  }
@Test public void testSignString() { String stringToSign = "1576478257344\n/configs/100004458/default/application?ip=10.0.0.1"; String accessKeySecret = "df23df3f59884980844ff3dada30fa97"; String actualSignature = HmacSha1Utils.signString(stringToSign, accessKeySecret); String expectedSignature = "EoKyziXvKqzHgwx+ijDJwgVTDgE="; assertEquals(expectedSignature, actualSignature); }