小编Lem*_*ngs的帖子

为什么我的PHP SHA256哈希不等同于C#SHA256Managed哈希

为什么这些不一样?

PHP:

    $hash = hash('sha256', $userData['salt'] . hash('sha256', $password) );
Run Code Online (Sandbox Code Playgroud)

C#

    public static string ComputeHash(string plainText, string salt)
    {
        // Convert plain text into a byte array.
        byte[] plainTextBytes = Encoding.UTF8.GetBytes(plainText);
        byte[] saltBytes = Encoding.UTF8.GetBytes(salt);

        SHA256Managed hash = new SHA256Managed();

        // Compute hash value of salt.
        byte[] plainHash = hash.ComputeHash(plainTextBytes);

        byte[] concat = new byte[plainHash.Length + saltBytes.Length];

        System.Buffer.BlockCopy(saltBytes, 0, concat, 0, saltBytes.Length);
        System.Buffer.BlockCopy(plainHash, 0, concat, saltBytes.Length, plainHash.Length);

        byte[] tHashBytes = hash.ComputeHash(concat);

        // Convert result into a base64-encoded string.
        string hashValue …
Run Code Online (Sandbox Code Playgroud)

php c# sha256

13
推荐指数
1
解决办法
1万
查看次数

标签 统计

c# ×1

php ×1

sha256 ×1