I'm trying to convert the following code that create encryption key to c# the result I need the $key ** and ** $iv
$passphrase = 'asdfghjkl';
$salt = '123456789' // for test purposes I fixed the value but it should be openssl_random_pseudo_bytes(8);
$salted = '';
$dx = '';
while (strlen($salted) < 48) {
$dx = md5($dx . $passphrase . $salt, true);
$salted .= $dx;
}
$key = substr($salted, 0, 32);
$iv = substr($salted, 32, 16);
what I could do until now
string passphrase = "asdfghjkl";
string salt = "123456789";
string key, iv;
byte[] salted = new byte[0];
byte[] dx = new byte[0];
while (salted.Length < 48)
{
string a = passphrase + salt;
byte[] b = Encoding.UTF8.GetBytes(a);
byte[] rv = new byte[dx.Length + b.Length];
System.Buffer.BlockCopy(dx, 0, rv, 0, dx.Length);
System.Buffer.BlockCopy(b, 0, rv, dx.Length, b.Length);
//dx = MD5CryptoServiceProvider.Create().ComputeHash(rv);
using (MD5 md5 = MD5.Create())
{
dx = md5.ComputeHash(rv);
}
byte[] rx = new byte[salted.Length + dx.Length];
System.Buffer.BlockCopy(salted, 0, rx, 0, salted.Length);
System.Buffer.BlockCopy(dx, 0, rx, salted.Length, dx.Length);
salted = rx;
}
string utfString1 = Encoding.UTF8.GetString(salted);
key = utfString1.Substring( 0, 32);
iv = utfString1.Substring(32, 16);
but I'm not getting the same result
thanks
passwod_hash()andpassword_verify().