dtmjqyfz21793 2011-02-11 12:30
浏览 102

如何将c#函数转换为php

How do I convert a C# function to a PHP function? The C# code is below:

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);
}
  • 写回答

3条回答 默认 最新

  • doudiecai1572 2011-02-11 12:37
    关注

    I'd say it's something like this:

    function encodePassword($password, $salt){
      return base64_encode(sha1($password . base64_decode($salt), true));
    }
    
    评论

报告相同问题?

悬赏问题

  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 有没有帮写代码做实验仿真的
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥30 vmware exsi重置后登不上
  • ¥15 易盾点选的cb参数怎么解啊
  • ¥15 MATLAB运行显示错误,如何解决?
  • ¥15 c++头文件不能识别CDialog
  • ¥15 Excel发现不可读取的内容
  • ¥15 关于#stm32#的问题:CANOpen的PDO同步传输问题
  • ¥20 yolov5自定义Prune报错,如何解决?