title: Compute HMAC-SHA512 with secret key in java
body: <p>I want to exactly build a function which produces a HMAC with a secret key like this site provides:</p>
  <p><a href="http://www.freeformatter.com/hmac-generator.html" rel="noreferrer">http://www.freeformatter.com/hmac-generator.html</a></p>
  <p>The Java 8 lib only provides MessageDigest and KeyGenerator which both only support up to SH256.</p>
  <p>Also, Google doesn't give me any result for an implementation to generate a HMAC.</p>
  <p>Does someone know a implementation?</p>
  <p>I have this code to generate an ordinary SH256 but I guess this doesn't help me much:</p>
  <pre><code>   public static String get_SHA_512_SecurePassword(String passwordToHash) throws Exception {
      String generatedPassword = null;
  
      MessageDigest md = MessageDigest.getInstance(&quot;SHA-512&quot;);
      byte[] bytes = md.digest(passwordToHash.getBytes(&quot;UTF-8&quot;));
      StringBuilder sb = new StringBuilder();
      for (int i = 0; i &lt; bytes.length; i++) {
          sb.append(Integer.toString((bytes[i] &amp; 0xff) + 0x100, 16).substring(1));
      }
      generatedPassword = sb.toString();
      System.out.println(generatedPassword);
      return generatedPassword;
  }
  </code></pre>