SoFunction
Updated on 2025-03-06

Small examples of calculating strings and file MD5 values


// Calculate the MD5 value of the string
        public string GetMD5(string sDataIn)
        {
            MD5CryptoServiceProvider md5 = new MD5CryptoServiceProvider();
            byte[] bytValue, bytHash;
            bytValue = .(sDataIn);
            bytHash = (bytValue);
            ();
            string sTemp = "";
            for (int i = 0; i < ; i++)
            {
                sTemp += bytHash[i].ToString("X").PadLeft(2, '0');
            }
            return ();
        }
       

//Calculate the MD5 value of the file
        public string MD5Value(String filepath)
        {
            MD5 md5 = new MD5CryptoServiceProvider();
            byte[] md5ch;
            using (FileStream fs = (filepath))
            {
                md5ch = (fs);
            }
            ();
            string strMd5 = "";
            for (int i = 0; i < - 1; i++)
            {
                strMd5 += md5ch[i].ToString("x").PadLeft(2, '0');
            }
            return strMd5;
        }