이 함수를 PHP로 변환하려고하는데, 어쨌든 같은 결과를 얻지 못합니다.C# 함수를 PHP5로 포트하려고 시도합니다.
public static string EncodePassword(string pass, string salt) {
byte[] bytes = Encoding.Unicode.GetBytes(pass);
byte[] src = Convert.FromBase64String(salt);
byte[] dst = new byte[src.Length + bytes.Length];
byte[] inArray = null;
Buffer.BlockCopy(src, 0, dst, 0, src.Length);
Buffer.BlockCopy(bytes, 0, dst, src.Length, bytes.Length);
HashAlgorithm algorithm = HashAlgorithm.Create("SHA1");
inArray = algorithm.ComputeHash(dst);
return Convert.ToBase64String(inArray);
}
이것은
function CreatePasswordHash($password, $salt) {
$salted_password = base64_decode($salt).$password;
$result = hash('SHA1',$salted_password,true);
return base64_encode($result);
}
물론이 작동하지 않습니다 PHP
에서이 걸릴 내입니다. 여기서 내가 뭘 잘못하고 있니?이
테스트에 대한 값은 다음과 같습니다$salt = 'Xh2pHwDv3VEUQCvz5qOm7w==';
$hashed_value = '0U/kYMz3yCXLsw/r9kocT5zf0cc=';
$password = 'Welcome1!';
if ($hashed_value === CreatePasswordHash($password,$salt)) {
echo "Good job!";
}
편집 : PHP와 C#과 C#을 출력 편지에 SHA1을 사용하면 있었다
function CreatePasswordHash($password, $salt) {
$upass = mb_convert_encoding($password,'UCS-2LE','auto');
$salted_password = base64_decode($salt).$upass;
$result = hash('SHA1',$salted_password,true);
return base64_encode($result);
}
귀하의 제안에 자리가있었습니다. 암호를 유니 코드로 변환해야하고 올바른 결과를 얻었습니다. 고마워요! –