gpt4 book ai didi

c# - 如何将 C# 函数转换为 PHP

转载 作者:行者123 更新时间:2023-12-01 00:07:21 24 4
gpt4 key购买 nike

如何将 C# 函数转换为 PHP 函数? C#代码如下:

internal string EncodePassword(string password, string salt)
{
// Get the Unicode bytes of the plain text password.
byte[] bytes = System.Text.Encoding.Unicode.GetBytes(password);

// The salt is a Base64 encoded string, convert back to a byte array.
byte[] src = Convert.FromBase64String(salt);

// Concat both byte buffers.
byte[] dst = new byte[src.Length + bytes.Length];
byte[] inArray = null;
System.Buffer.BlockCopy(src, 0, dst, 0, src.Length);
System.Buffer.BlockCopy(bytes, 0, dst, src.Length, bytes.Length);

// Compute the SHA1-hash from the concatenated buffer.
System.Security.Cryptography.SHA1 algorithm = System.Security.Cryptography.SHA1Managed.Create();
inArray = algorithm.ComputeHash(dst);

// Return the result as a Base64-string.
return Convert.ToBase64String(inArray);
}

最佳答案

我知道现在回答这个问题已经太晚了。但我认为这对试图将 C# 代码转换为 PHP 的人会有帮助。我最近有类似的需求

<?php

$password ='test123';
$salt = '5Br2nXb56EpliGXmfHdWWw==';

$password = mb_convert_encoding($password,'UTF-16LE');
echo base64_encode(sha1(base64_decode($salt).$password,true));

关于c# - 如何将 C# 函数转换为 PHP,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4968991/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com