Guest User

Untitled

a guest
Feb 20th, 2018
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.35 KB | None | 0 0
  1. public static string Md5FromFile(string input)
  2. {
  3. string saida = null;
  4. using (System.Security.Cryptography.MD5 md5Hasher = System.Security.Cryptography.MD5.Create())
  5. {
  6. Byte[] bytes = System.IO.File.ReadAllBytes(input);
  7. Byte[] data = md5Hasher.ComputeHash(bytes);
  8. StringBuilder sBuilder = new StringBuilder();
  9. foreach (var valorByte in data)
  10. sBuilder.Append(valorByte.ToString("x2"));
  11.  
  12. saida = sBuilder.ToString();
  13. }
  14. return saida.ToString();
  15. }
  16.  
  17. public string GetMd5FromSite(string arquivo)
  18. {
  19. NameValueCollection nvc;
  20. nvc = new NameValueCollection();
  21. nvc.Add("arquivo", arquivo);
  22. System.Net.WebClient client = new System.Net.WebClient();
  23. string URL = "http://www.seudominio.com.br/pasta/md5.php";
  24. WebProxy myProxy = new WebProxy();
  25. myProxy.BypassProxyOnLocal = true;
  26. client.Proxy = myProxy;
  27. byte[] responseArray = client.UploadValues(URL, nvc);
  28. return new System.Text.ASCIIEncoding().GetString(responseArray);
  29. }
  30.  
  31. <?php
  32. function fmd5($p_arquivo)
  33. {
  34. return md5_file($p_arquivo);
  35. }
  36.  
  37. echo fmd5($_POST['arquivo']);
  38. ?>
  39.  
  40. string md5Local = Md5FromFile(Application.StartupPath+"\arquivo.txt");
  41. string md5Site = GetMd5FromSite("arquivo.txt"); //considerando que o arquivo está no mesmo diretório do md5.php
  42.  
  43. if (md5Local != md5Site)
  44. {
  45. //faz o download
  46. }
Add Comment
Please, Sign In to add comment