Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static string Md5FromFile(string input)
- {
- string saida = null;
- using (System.Security.Cryptography.MD5 md5Hasher = System.Security.Cryptography.MD5.Create())
- {
- Byte[] bytes = System.IO.File.ReadAllBytes(input);
- Byte[] data = md5Hasher.ComputeHash(bytes);
- StringBuilder sBuilder = new StringBuilder();
- foreach (var valorByte in data)
- sBuilder.Append(valorByte.ToString("x2"));
- saida = sBuilder.ToString();
- }
- return saida.ToString();
- }
- public string GetMd5FromSite(string arquivo)
- {
- NameValueCollection nvc;
- nvc = new NameValueCollection();
- nvc.Add("arquivo", arquivo);
- System.Net.WebClient client = new System.Net.WebClient();
- string URL = "http://www.seudominio.com.br/pasta/md5.php";
- WebProxy myProxy = new WebProxy();
- myProxy.BypassProxyOnLocal = true;
- client.Proxy = myProxy;
- byte[] responseArray = client.UploadValues(URL, nvc);
- return new System.Text.ASCIIEncoding().GetString(responseArray);
- }
- <?php
- function fmd5($p_arquivo)
- {
- return md5_file($p_arquivo);
- }
- echo fmd5($_POST['arquivo']);
- ?>
- string md5Local = Md5FromFile(Application.StartupPath+"\arquivo.txt");
- string md5Site = GetMd5FromSite("arquivo.txt"); //considerando que o arquivo está no mesmo diretório do md5.php
- if (md5Local != md5Site)
- {
- //faz o download
- }
Add Comment
Please, Sign In to add comment