PHP相当于下面的sha1加密c#代码


php equivalent to following sha1 encryption c# code

我尝试将以下c#代码转换为sha1密码加密检查到PHP版本,但似乎失败了:

在我的理解中这段代码-> 1)编码成ASCII 2)存储在字节数组中3)加密字节数组为sha1并再次存储在字节数组中新的字节[60]4)转换字节数组为64位字符串。我无法在以下代码中获得字节字符串部分。

 private static string ComputeHas(byte[] arry){
    StringBuilder sb = new StringBuilder(arry.Length);
    return Convert.ToBase64String(arry);
}
public static string SHA1HashEncode(string pwd)
{
    SHA1 sh = new SHA1CryptoServiceProvider();
    byte[] arr = new byte[60];
    string hash = "";
    byte[] array = Encoding.ASCII.GetBytes(pwd);
    arr = sh.ComputeHash(array);
    hash = ComputeHas(arr);
    return hash;
}

这是我尝试的:

//convert string to ascii 
for($i = 0; $i < mb_strlen($pwd, 'ASCII'); $i++) {
$pwd1=ord($pwd[$i]); 
} 
//sha1 encryption of password 
$pwd2=sha1($pwd1);

我已经尝试到目前为止得到可能的确切如下://将字符串转换为ascii

for($i = 0; $i < mb_strlen($pwd, 'ASCII'); $i++)
{
    $pwd1=ord($pwd[$i]);
    $pwd2[]=$pwd1; 
}
//convert array to string
$pwdString = serialize($pwd2);
//compute hase of string
$pwdHash= array();
$pwdHash[]=array_fill(0,60,sha1($pwdString));
$pwdHashString=serialize($pwdHash);
//convert to 64 bit string encodeing
$pwd64encode=base64_encode($pwdHashString);
print_r($pwd64encode);

但我没有得到确切的c#代码在php

来自PHP关于SHA1的文档

$variable = sha1("input");