Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.IO;
- using System.Security.Cryptography;
- using System.Text;
- namespace artem_laba
- {
- class Program
- {
- public static string PrintBytes(byte[] hashBytes)
- {
- StringBuilder sb = new StringBuilder();
- foreach (var t in hashBytes)
- {
- sb.Append(t.ToString("X2").ToLower());
- }
- return sb.ToString();
- }
- public static string GenMD5(string inp)
- {
- MD5 md5 = MD5.Create();
- byte[] hashBytes = md5.ComputeHash(Encoding.UTF8.GetBytes(inp));
- return PrintBytes(hashBytes);
- }
- static void Main(string[] args)
- {
- // open file
- string path;
- do
- {
- Console.Write("Enter path: ");
- path = Console.ReadLine();
- path = path.Trim();
- } while (path == "");
- // проверка абсолютный или относительный путь
- bool absolute = path.Contains('\\');
- if (!absolute)
- path = Path.GetFullPath(path).ToString();
- Console.WriteLine(path);
- // читаем из файла
- try
- {
- using StreamReader sr = new StreamReader(path);
- string context = sr.ReadToEnd();
- // шифруем
- string encrypted = GenMD5(context);
- Console.WriteLine(encrypted);
- }
- catch (Exception e)
- {
- Console.WriteLine(e.Message);
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement