代码如下,求翻译成PHP代码: public string GenerateSalt()
{
byte[] array = new byte[16];
new RNGCryptoServiceProvider().GetBytes(array);
return Convert.ToBase64String(array);
}
public string EncodePassword(string pass, int passwordFormat, string salt)
{
if (passwordFormat == 0)
{
return pass;
}
byte[] bytes = Encoding.Unicode.GetBytes(pass);
byte[] array = Convert.FromBase64String(salt);
byte[] array2 = new byte[array.Length + bytes.Length];
System.Buffer.BlockCopy(array, 0, array2, 0, array.Length);
System.Buffer.BlockCopy(bytes, 0, array2, array.Length, bytes.Length);
byte[] inArray;
HashAlgorithm hashAlgorithm = HashAlgorithm.Create(Membership.HashAlgorithmType);
inArray = hashAlgorithm.ComputeHash(array2);
return Convert.ToBase64String(inArray);
}
{
byte[] array = new byte[16];
new RNGCryptoServiceProvider().GetBytes(array);
return Convert.ToBase64String(array);
}
public string EncodePassword(string pass, int passwordFormat, string salt)
{
if (passwordFormat == 0)
{
return pass;
}
byte[] bytes = Encoding.Unicode.GetBytes(pass);
byte[] array = Convert.FromBase64String(salt);
byte[] array2 = new byte[array.Length + bytes.Length];
System.Buffer.BlockCopy(array, 0, array2, 0, array.Length);
System.Buffer.BlockCopy(bytes, 0, array2, array.Length, bytes.Length);
byte[] inArray;
HashAlgorithm hashAlgorithm = HashAlgorithm.Create(Membership.HashAlgorithmType);
inArray = hashAlgorithm.ComputeHash(array2);
return Convert.ToBase64String(inArray);
}
$s = pack('L*', rand(), rand(), rand(), rand());
return base64_encode($s);
}
function EncodePassword($pass, $passwordFormat, $salt) {
if($passwordFormat ==0) return $pass;
$s = $pass . base64_decode($salt);
return base64_encode(sha1($s));
}