Shiyan12

MD5

Jul 2nd, 2021
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.97 KB | None | 0 0
  1. using System;
  2. using System.IO;
  3. using System.Security.Cryptography;
  4. using System.Text;
  5.  
  6. namespace ConsoleApp1
  7. {
  8.     class Program
  9.     {
  10.         static void Main(string[] args)
  11.         {
  12.             string input;
  13.             if (args.Length == 0)
  14.             {
  15.                 input = Console.ReadLine();
  16.             }
  17.             else
  18.             {
  19.                 input = args[0];
  20.             }
  21.  
  22.             MD5 md5 = MD5.Create();
  23.             byte[] hash = md5.ComputeHash(Encoding.UTF8.GetBytes(input));
  24.  
  25.             string output = Convert.ToBase64String(hash);
  26.  
  27.             string writePath = "hash.txt";
  28.             try
  29.             {
  30.                 using (StreamWriter sw = new StreamWriter(writePath, false, Encoding.Default))
  31.                 {
  32.                     sw.WriteLine(output);
  33.                 }
  34.             }
  35.             catch (Exception e)
  36.             {
  37.                 Console.WriteLine(e.Message);
  38.             }
  39.         }
  40.     }
  41. }
  42.  
Add Comment
Please, Sign In to add comment