Advertisement
Guest User

Untitled

a guest
Jan 16th, 2018
178
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.33 KB | None | 0 0
  1. using System;
  2. using System.IO;
  3. using System.Security.Cryptography;
  4. using System.Text;
  5.  
  6. namespace opisafaggot
  7. {
  8.     class Program
  9.     {
  10.         // use "C:\\path\\to\\stuff" for Windows
  11.         // use "/path/to/stuff" for Linux/Mac
  12.         static string inputDir = "/path/to/stuff/asc";
  13.         static string outputDir = "/path/to/stuff/decrypted";
  14.         static string md5Dir = "/path/to/stuff/asc_md5";
  15.         static string passwordsTxt = "/path/to/stuff/passwords.txt";
  16.  
  17.         static void Main(string[] args)
  18.         {
  19.             string[] passwords = File.ReadAllLines(passwordsTxt);
  20.  
  21.             if (!Directory.Exists(outputDir))
  22.                 Directory.CreateDirectory(outputDir);
  23.            
  24.             for (int i = 1; i <= 61; i++)
  25.             {
  26.                 string input = Path.Combine(inputDir, String.Format("{0}.aes", i));
  27.                 string output = Path.Combine(outputDir, String.Format("{0}.png", i));
  28.                 string md5File = Path.Combine(md5Dir, String.Format("{0}.txt", i));
  29.                 string md5 = File.ReadAllLines(md5File)[3].Split(' ')[0];
  30.  
  31.                 if (File.Exists(input))
  32.                 {
  33.                     DecryptFile(input, output, passwords[i + 2], md5);
  34.                 }
  35.                 else
  36.                 {
  37.                     Console.WriteLine("\"{0}\" doesn't exist!", input);
  38.                 }
  39.             }
  40.         }
  41.  
  42.         static byte[] AES_Decrypt(byte[] bytesToBeDecrypted, byte[] passwordBytes)
  43.         {
  44.             byte[] decryptedBytes = null;
  45.  
  46.             byte[] saltBytes = new byte[] { 1, 2, 3, 4, 5, 6, 7, 8 };
  47.  
  48.             using (MemoryStream ms = new MemoryStream())
  49.             {
  50.                 using (AesManaged AES = new AesManaged())
  51.                 {
  52.                     var key = new Rfc2898DeriveBytes(passwordBytes, saltBytes, 1000);
  53.                     AES.Key = key.GetBytes(AES.KeySize / 8);
  54.                     AES.IV = key.GetBytes(AES.BlockSize / 8);
  55.  
  56.                     using (var cs = new CryptoStream(ms, AES.CreateDecryptor(), CryptoStreamMode.Write))
  57.                     {
  58.                         cs.Write(bytesToBeDecrypted, 0, bytesToBeDecrypted.Length);
  59.                         cs.Close();
  60.                     }
  61.                     decryptedBytes = ms.ToArray();
  62.                 }
  63.             }
  64.  
  65.             return decryptedBytes;
  66.         }
  67.  
  68.         static void DecryptFile(string input, string output, string password, string hash)
  69.         {
  70.             Console.WriteLine("Decrypting \"{0}\" to \"{1}\" with password \"{2}\"", input, output, password);
  71.  
  72.             byte[] bytesToBeDecrypted = File.ReadAllBytes(input);
  73.             byte[] passwordBytes = Encoding.UTF8.GetBytes(password);
  74.             passwordBytes = SHA256.Create().ComputeHash(passwordBytes);
  75.  
  76.             byte[] bytesDecrypted = AES_Decrypt(bytesToBeDecrypted, passwordBytes);
  77.  
  78.             Console.WriteLine("MD5 verified: {0}", VerifyMD5(hash, bytesDecrypted));
  79.  
  80.             File.WriteAllBytes(output, bytesDecrypted);
  81.         }
  82.  
  83.         static bool VerifyMD5(string hash, byte[] bytesDecrypted)
  84.         {
  85.             byte[] computed = MD5.Create().ComputeHash(bytesDecrypted);
  86.             string computedHash = BitConverter.ToString(computed).Replace("-", string.Empty).ToLower();
  87.             return (hash == computedHash);
  88.         }
  89.     }
  90. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement