title: C# HMAC to Java
body: <p>I'm making the equivalent java code for the code below. But I can make something that returns the same result for <strong>encodedString</strong>. What Java class can I use for achieve the same result?</p>
  
  <pre><code>//Set the Hash method to SHA1
  HMAC hash;
  switch (validation)
  {
      case MachineKeyValidation.MD5:
          hash = new HMACMD5();
          break;
      case MachineKeyValidation.SHA1:
      default:
          hash = new HMACSHA1();
          break;
  }
  //Get the hash validation key as an array of bytes
  hash.Key = HexToByte(validationKey);
  //Encode the password based on the hash key and
  //converts the encrypted value into a string
  encodedString = Convert.ToBase64String(hash.ComputeHash(Encoding.Unicode.GetBytes(password)));
  </code></pre>
  
  <p>Thanks in advance!
  :)</p>