Hi,
I would like to ask how to convert this C# code into PHP as my office application is in WinForm C# but need to have a PHP portal for it?
[code]public string HashString(string toHash)
{
using (SHA512CryptoServiceProvider sha = new SHA512CryptoServiceProvider())
{
byte[] dataToHash = Encoding.UTF8.GetBytes(toHash);
byte[] hashed = sha.ComputeHash(dataToHash);
return Convert.ToBase64String(hashed);
}
}
public string HashPassword(string password, string salt)
{
string combined = password + salt;
return HashString(combined);
}
[/code]
I tried this but I am not getting the correct hash I got from C# .NET:
[php]<?php
$salt = “f0ef0e366a254bde8d561baba8cebd6fdcc4c7aa5f814a15a97f497a2b82a2d8”;
$data = “testpasswordf0ef0e366a254bde8d561baba8cebd6fdcc4c7aa5f814a15a97f497a2b82a2d8”;
echo base64_encode(hash(‘sha512’, $data));
?>[/php]
so I am getting:
NzRiY2EyZmU2YTFjOGJhNzhkY2NiODc2ZmRjYjRhZTBkNjQ2YzEyZTI5NzQ3MmNmZWZlNWRkOWNiNDdmN2VhNzc2ZjcxNzk5OTRkMDM1ZTgxZmRiYzRiZGI4NjUyYWQ1MjFkMzQzNGRlODg2YjZlOGUzNDEzZmRhZTRhYmVkMjQ
where I should get:
dLyi/moci6eNzLh2/ctK4NZGwS4pdHLP7+XdnLR/fqd29xeZlNA16B/bxL24ZSrVIdNDTeiGtujjQT/a5KvtJA==
can anyone help please?
Thanks,
Jassim