使用sha256managed解密哈希

问题描述 投票:-1回答:4

好吧,一周前我开始使用c#,我有点困惑。

我从加密开始,基本上是哈希和盐。

我的老师给了我们这个周末做的“功课”,我和我的所有伙伴都非常困惑。

我有这个简单的代码:

练习包括“解密”散列密码(使用SHA256managed进行哈希处理),我们知道它是一个4个字符的数字。

我尝试使用循环并逐个解密所有字符,但我卡住了,我不知道如何继续。

如果你能帮助我,我真的很感激。

谢谢!

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Security.Cryptography;
using System.IO;

namespace Examen
{
    class Program
    {
        static void Main(string[] args)
        {

            string hashed_password = "YOSGtSkJ41KX7K80FEmg+vme4ioLsp3qr28XU8nDQ9c=";



            Console.ReadLine();
        }


    }
}
c# encryption hash
4个回答
1
投票

我的方法是做一个蛮力,因为你说你已经知道它是一个4位数字。

你可以这样做:

  static void Main(string[] args)
    {
        string hashed = "YOSGtSkJ41KX7K80FEmg+vme4ioLsp3qr28XU8nDQ9c=";

        for (int i = 1000; i <=9999; i++)
        {
            string digit = i.ToString().PadLeft(4, '0');
            string s = ComputeSHA256(digit);
            if (s == hashed)
            {
                Console.WriteLine(digit + "is my decrypted hash");
                break;
            }
        }
        Console.ReadKey();
    }

    static string ComputeSHA256(string plainText)
    {
         SHA256Managed sha256Managed = new SHA256Managed();
        Encoding u16LE = Encoding.Unicode;
        string hash = String.Empty;
        byte[] hashed = sha256Managed.ComputeHash(u16LE.GetBytes(plainText), 0, u16LE.GetByteCount(plainText));
        return Convert.ToBase64String(hashed);
    }
© www.soinside.com 2019 - 2024. All rights reserved.