'How to replicate ASP Classic SHA512 Hash function in PHP

I'm currently rewriting an asp classic site in PHP, everything so far has been simple until I reached the password hashing function. In PHP I've used hash_hmac and hash, but I seem unable to replicate this functions results using a static salt in PHP. Please could someone help guide me as to how to produce the same result in PHP?

<%  Function Hash(strPassword, strIndividualSalt)

  Const strSiteWideSalt = "Bacon and HASH is best served with a good Salt!"
  Hash = HashSHA512Managed(strSiteWideSalt & strPassword & strIndividualSalt)

End Function

Function HashSHA512Managed(saltedPassword)

  Dim objMD5, objUTF8
  Dim arrByte
  Dim strHash
  Set objUnicode = CreateObject("System.Text.UnicodeEncoding")
  Set objSHA512 = Server.CreateObject("System.Security.Cryptography.SHA512Managed")

  arrByte = objUnicode.GetBytes_4(saltedPassword)
  strHash = objSHA512.ComputeHash_2((arrByte))

  HashSHA512Managed = ToBase64(strHash)

End Function

Function ToBase64(rabyt)
    Dim xml: Set xml = CreateObject("MSXML2.DOMDocument.3.0")
    xml.LoadXml "<root />"
    xml.documentElement.dataType = "bin.base64"
    xml.documentElement.nodeTypedValue = rabyt
    ToBase64 = xml.documentElement.Text
End Function
response.write  Hash("mypassword", "mysalt")%>

This outputs...

1Asf3PuLZetBni4laI7jDKG3fbhlzKzB41G2694oZdH6nELLXklqtvY8Tniqjf3/2/gGg01fzs4w67l1Tfs20A==

Should I be using hash_hmac? Or do I need to replicate the function in PHP using hash()? Any help would be appreciated.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source