Is there a way to test if a string is an MD5 hash?

前端 未结 6 967
误落风尘
误落风尘 2020-12-16 20:38

I am trying to input a text file that contains MD5 hashes and keywords (one per line) into a C# app. Is there a way to check if a string is an MD5 hash? I looked on MSDN a

6条回答
  •  余生分开走
    2020-12-16 21:13

    Use Regex like this:

    public static bool IsMD5(string input)
    {
        if (String.IsNullOrEmpty(input))
        {
            return false;
        }
    
        return Regex.IsMatch(input, "^[0-9a-fA-F]{32}$", RegexOptions.Compiled);
    }
    

提交回复
热议问题