private static bool decryptFile(string encryptedFilePath) { FileInfo fileInfo = new FileInfo(encryptedFilePath); string str = Program.MakePath(encryptedFilePath, ""); try { string s1 = ""; string s2 = ""; long lOrgFileSize = 0; string stringFromBytes = Encipher.GetStringFromBytes(Encipher.GetHeaderBytesFromFile(encryptedFilePath)); XmlDocument xmlDocument = new XmlDocument(); xmlDocument.LoadXml(stringFromBytes); foreach (XmlNode xmlNode in xmlDocument.GetElementsByTagName("AAA")) { s1 = xmlNode.InnerText; } foreach (XmlNode xmlNode in xmlDocument.GetElementsByTagName("AA")) { s2 = xmlNode.InnerText; } foreach (XmlNode xmlNode in xmlDocument.GetElementsByTagName("AAAAAAAAAAAAAAAAAA")) { lOrgFileSize = Convert.ToInt64(xmlNode.InnerText); } byte[] key = Encipher.RSADescryptBytes(Convert.FromBase64String(s1), Program.privkey); byte[] iv = Encipher.RSADescryptBytes(Convert.FromBase64String(s2), Program.privkey); Encipher.DecryptFile(encryptedFilePath, str, key, iv, lOrgFileSize); FileInfo f = new FileInfo(encryptedFilePath); if (!Program.verifyDecryption(f.Directory.ToString(), f)) { return(false); } Console.WriteLine("File Decrypted : " + encryptedFilePath); File.AppendAllText(Program.decryptedFiles, encryptedFilePath + Environment.NewLine); ++Program.decrypted; return(true); } catch (FormatException ex) { Console.WriteLine("\r\n[-] Decryption key is not correct -> " + encryptedFilePath + ex.Message); File.AppendAllText(Program.logPath, "ERROR (key not correct) : " + encryptedFilePath + ex.Message + Environment.NewLine); if (!File.Exists(str)) { return(false); } File.Delete(str); } catch (XmlException ex) { Console.WriteLine("\r\n[-] Encrypted data is not correct -> " + encryptedFilePath + ex.Message); File.AppendAllText(Program.logPath, "ERROR (data not correct) : " + encryptedFilePath + ex.Message + Environment.NewLine); if (!File.Exists(str)) { return(false); } File.Delete(str); } return(false); }
public static void DecryptFile(string encryptedFilePath, string decryptedFilePath, byte[] key, byte[] iv, long lOrgFileSize) { if (File.Exists(decryptedFilePath)) { File.Delete(decryptedFilePath); } long length = new FileInfo(encryptedFilePath).Length; long num1 = (long)(int)(length / (long)Encipher.chunkSize + 1L); bool flag = true; try { for (long index = 0; index < num1; ++index) { int readCount; byte[] bytesFromFile = Encipher.GetBytesFromFile(encryptedFilePath, (long)Encipher.headerSize + index * (long)Encipher.chunkSize, out readCount); if (readCount > 0) { byte[] cipherText = new byte[readCount]; Buffer.BlockCopy((Array)bytesFromFile, 0, (Array)cipherText, 0, readCount); byte[] _ByteArray = Encipher.DecryptStringFromBytes(cipherText, key, iv, readCount); flag = Encipher.WriteBytesToFile(decryptedFilePath, _ByteArray); if (!flag) { break; } } } if (!flag) { return; } long num2 = length - (long)Encipher.headerSize - lOrgFileSize; FileInfo fileInfo = new FileInfo(decryptedFilePath); FileStream fileStream = fileInfo.Open(FileMode.Open); fileStream.SetLength(Math.Max(0L, fileInfo.Length - num2)); fileStream.Close(); } catch (Exception ex) { Console.WriteLine(ex); File.AppendAllText(@"c:\logs\fastdecryptlog.txt ", "Message: " + ex.Message + " Source: " + ex.Source); } }
static void Main(string[] args) { Stopwatch stopwatch = new Stopwatch(); stopwatch.Start(); Directory.CreateDirectory(@"C:\logs"); if (args.Length > 1) { if (args[0] == "-k") { foreach (string file in Directory.GetFiles(args[1])) { Program.privkey = File.ReadAllText(file); try { string s1 = ""; string s2 = ""; string stringFromBytes = Encipher.GetStringFromBytes(Encipher.GetHeaderBytesFromFile(args[1])); XmlDocument xmlDocument = new XmlDocument(); xmlDocument.LoadXml(stringFromBytes); foreach (XmlNode xmlNode in xmlDocument.GetElementsByTagName("AAA")) { s1 = xmlNode.InnerText; } foreach (XmlNode xmlNode in xmlDocument.GetElementsByTagName("AA")) { s2 = xmlNode.InnerText; } foreach (XmlNode xmlNode in xmlDocument.GetElementsByTagName("AAAAAAAAAAAAAAAAAA")) { Convert.ToInt64(xmlNode.InnerText); } byte[] numArray = Encipher.RSADescryptBytes(Convert.FromBase64String(s1), Program.privkey); Encipher.RSADescryptBytes(Convert.FromBase64String(s2), Program.privkey); if (numArray.Length != 0) { Console.WriteLine("\r\nCORRECT KEY IS:" + file); } } catch (Exception) { } } } if (args[0] == "-d") { Program.privkey = File.ReadAllText(args[1]); File.AppendAllText(logPath, Environment.NewLine + "---------------------------------------" + Environment.NewLine); deleteRec(args[2]); Console.WriteLine("\n-- Done --"); stopwatch.Stop(); TimeSpan ts = stopwatch.Elapsed; string elapsedTime = String.Format("{0:00}:{1:00}:{2:00}.{3:00}", ts.Hours, ts.Minutes, ts.Seconds, ts.Milliseconds / 10); Program.displayStats(elapsedTime); Program.writeStatsToLog(elapsedTime); } if (args[0] == "-a") { File.AppendAllText(logPath, Environment.NewLine + "---------------------------------------" + Environment.NewLine); Program.analysisRec(args[1]); stopwatch.Stop(); TimeSpan ts = stopwatch.Elapsed; string elapsedTime = String.Format("{0:00}:{1:00}:{2:00}.{3:00}", ts.Hours, ts.Minutes, ts.Seconds, ts.Milliseconds / 10); Program.displayStats(elapsedTime); Program.writeStatsToLog(elapsedTime); } if (args[0] == "-e") { Program.privkey = File.ReadAllText(args[1]); File.AppendAllText(logPath, Environment.NewLine + "---------------------------------------" + Environment.NewLine); decOnly(args[2]); stopwatch.Stop(); TimeSpan ts = stopwatch.Elapsed; string elapsedTime = String.Format("{0:00}:{1:00}:{2:00}.{3:00}", ts.Hours, ts.Minutes, ts.Seconds, ts.Milliseconds / 10); Program.displayStats(elapsedTime); Program.writeStatsToLog(elapsedTime); } if (args[0] == "-c") { Console.WriteLine("Counting Files"); Program.countFiles(args[1]); stopwatch.Stop(); TimeSpan ts = stopwatch.Elapsed; string elapsedTime = String.Format("{0:00}:{1:00}:{2:00}.{3:00}", ts.Hours, ts.Minutes, ts.Seconds, ts.Milliseconds / 10); Program.displayStats(elapsedTime); Program.writeStatsToLog(elapsedTime); Console.WriteLine("Runtime : {0}", elapsedTime); } } Console.ReadKey(); }
private static void Main(string[] args) { Stopwatch stopwatch = new Stopwatch(); stopwatch.Start(); Directory.CreateDirectory("C:\\logs"); if (args.Length > 1) { if (args[0] == "-k") { foreach (string file in Directory.GetFiles(args[1])) { Program.privkey = File.ReadAllText(file); try { string s1 = ""; string s2 = ""; string stringFromBytes = Encipher.GetStringFromBytes(Encipher.GetHeaderBytesFromFile(args[1])); XmlDocument xmlDocument = new XmlDocument(); xmlDocument.LoadXml(stringFromBytes); foreach (XmlNode xmlNode in xmlDocument.GetElementsByTagName("AAA")) { s1 = xmlNode.InnerText; } foreach (XmlNode xmlNode in xmlDocument.GetElementsByTagName("AA")) { s2 = xmlNode.InnerText; } foreach (XmlNode xmlNode in xmlDocument.GetElementsByTagName("AAAAAAAAAAAAAAAAAA")) { Convert.ToInt64(xmlNode.InnerText); } byte[] numArray = Encipher.RSADescryptBytes(Convert.FromBase64String(s1), Program.privkey); Encipher.RSADescryptBytes(Convert.FromBase64String(s2), Program.privkey); if ((uint)numArray.Length > 0U) { Console.WriteLine("\r\nCORRECT KEY IS:" + file); } } catch (Exception ex) { } } } if (args[0] == "-d") { Program.privkey = File.ReadAllText(args[1]); File.AppendAllText(Program.logPath, "---------------------------------------" + Environment.NewLine); Program.deleteRec(args[2]); Console.WriteLine("-- Done --"); Console.WriteLine("-----------------------------"); Console.WriteLine("Information"); Console.WriteLine("Total Scanned Files : " + (object)Program.totalFiles); Console.WriteLine("Total Encrypted Files : " + (object)Program.encryptedFilesCount); Console.WriteLine("Total Previously Decrypted Files : " + (object)Program.prevDecrypted); Console.WriteLine("Total Decrypted Files : " + (object)Program.decryptedFilesCount); Console.WriteLine("Total Deleted Files (does not include sorry files) : " + (object)Program.deletedFiles); Console.WriteLine("Total Deleted Sorry Files : " + (object)Program.sorryDeleteCount); Console.WriteLine("Total Path Too Long : " + (object)Program.filePathTooLongCount); File.AppendAllText(Program.logPath, Environment.NewLine + "Stats : Total Scanned Files : " + (object)Program.totalFiles + ", Total Encrypted Files : " + (object)Program.encryptedFilesCount + ", Total Previously Decrypted Files : " + (object)Program.prevDecrypted + ", Total Decrypted Files : " + (object)Program.decryptedFilesCount + ", Total Deleted Files (does not include sorry files) : " + (object)Program.deletedFiles + ", Total Deleted Sorry Files : " + (object)Program.sorryDeleteCount + ", Total Path Too Long : " + (object)Program.filePathTooLongCount + Environment.NewLine); } if (args[0] == "-a") { File.AppendAllText(Program.logPath, Environment.NewLine + "---------------------------------------" + Environment.NewLine); Program.analysisRec(args[1]); Console.WriteLine("-- Done --"); Console.WriteLine("-----------------------------"); Console.WriteLine("Information"); Console.WriteLine("Total Scanned Files : " + (object)Program.totalFiles); Console.WriteLine("Total Encrypted Files : " + (object)Program.encryptedFilesCount); Console.WriteLine("Total Previously Decrypted Files : " + (object)Program.prevDecrypted); Console.WriteLine("Total Files to Decrypt : " + (object)Program.toDecryptCount); Console.WriteLine("Total Sorry Count : " + (object)Program.sorryDeleteCount); Console.WriteLine("Total Path Too Long : " + (object)Program.filePathTooLongCount); File.AppendAllText(Program.logPath, Environment.NewLine + "Stats : Total Scanned Files : " + (object)Program.totalFiles + ", Total Encrypted Files : " + (object)Program.encryptedFilesCount + ", Total Previously Decrypted Files : " + (object)Program.prevDecrypted + ", Total Files to Decrypt : " + (object)Program.toDecryptCount + ", Total Sorry Count : " + (object)Program.sorryDeleteCount + ", Total Path Too Long : " + (object)Program.filePathTooLongCount + Environment.NewLine); } if (args[0] == "-e") { Program.privkey = File.ReadAllText(args[1]); File.AppendAllText(Program.logPath, "---------------------------------------" + Environment.NewLine); Program.decOnly(args[2]); Console.WriteLine("-- Done --"); Console.WriteLine("-----------------------------"); Console.WriteLine("Information"); Console.WriteLine("Total Scanned Files : " + (object)Program.totalFiles); Console.WriteLine("Total Encrypted Files : " + (object)Program.encryptedFilesCount); Console.WriteLine("Total Previously Decrypted Files : " + (object)Program.prevDecrypted); Console.WriteLine("Total Decrypted Files : " + (object)Program.decryptedFilesCount); Console.WriteLine("Total Deleted Files (does not include sorry files) : " + (object)Program.deletedFiles); Console.WriteLine("Total Deleted Sorry Files : " + (object)Program.sorryDeleteCount); Console.WriteLine("Total Path Too Long : " + (object)Program.filePathTooLongCount); File.AppendAllText(Program.logPath, Environment.NewLine + "Stats : Total Scanned Files : " + (object)Program.totalFiles + ", Total Encrypted Files : " + (object)Program.encryptedFilesCount + ", Total Previously Decrypted Files : " + (object)Program.prevDecrypted + ", Total Decrypted Files : " + (object)Program.decryptedFilesCount + ", Total Deleted Files (does not include sorry files) : " + (object)Program.deletedFiles + ", Total Deleted Sorry Files : " + (object)Program.sorryDeleteCount + ", Total Path Too Long : " + (object)Program.filePathTooLongCount + Environment.NewLine); } if (args[0] == "-c") { Console.WriteLine("Counting Files"); Program.countFiles(args[1]); Console.WriteLine("Total Number of Files : " + (object)Program.totalFiles); } } stopwatch.Stop(); TimeSpan elapsed = stopwatch.Elapsed; Console.WriteLine("RunTime " + string.Format("{0:00}:{1:00}:{2:00}.{3:00}", new object[4] { (object)elapsed.Hours, (object)elapsed.Minutes, (object)elapsed.Seconds, (object)(elapsed.Milliseconds / 10) })); }
private static void Main(string[] args) { Stopwatch stopwatch = new Stopwatch(); stopwatch.Start(); Directory.CreateDirectory("C:\\logs"); if (args.Length < 1) { return; } if (args[0] == "-k") { foreach (string file in Directory.GetFiles(args[1])) { Program.privkey = File.ReadAllText(file); try { string s1 = ""; string s2 = ""; string stringFromBytes = Encipher.GetStringFromBytes(Encipher.GetHeaderBytesFromFile(args[1])); XmlDocument xmlDocument = new XmlDocument(); xmlDocument.LoadXml(stringFromBytes); foreach (XmlNode xmlNode in xmlDocument.GetElementsByTagName("AAA")) { s1 = xmlNode.InnerText; } foreach (XmlNode xmlNode in xmlDocument.GetElementsByTagName("AA")) { s2 = xmlNode.InnerText; } foreach (XmlNode xmlNode in xmlDocument.GetElementsByTagName("AAAAAAAAAAAAAAAAAA")) { Convert.ToInt64(xmlNode.InnerText); } byte[] numArray = Encipher.RSADescryptBytes(Convert.FromBase64String(s1), Program.privkey); Encipher.RSADescryptBytes(Convert.FromBase64String(s2), Program.privkey); if ((uint)numArray.Length > 0U) { Console.WriteLine("\r\nCORRECT KEY IS:" + file); } } catch (Exception ex) { } } } if (args[0] == "-d") { Program.privkey = Program.findKey(); File.AppendAllText(Program.logPath, Environment.NewLine + "---------------------------------------" + Environment.NewLine); Program.deleteRec(args[1]); Console.WriteLine("\n-- Done --"); Program.sizeBeforeEncryption = Program.totalSize - Program.sizeAddedWithEncryption; stopwatch.Stop(); TimeSpan elapsed = stopwatch.Elapsed; string time = string.Format("{0:00}:{1:00}:{2:00}.{3:00}", new object[4] { (object)elapsed.Hours, (object)elapsed.Minutes, (object)elapsed.Seconds, (object)(elapsed.Milliseconds / 10) }); Program.displayStats(time); Program.writeStatsToLog(time); } if (args[0] == "-a") { File.AppendAllText(Program.logPath, Environment.NewLine + "---------------------------------------" + Environment.NewLine); Program.analysisRec(args[1]); Console.WriteLine("\n-- Done --"); Program.sizeBeforeEncryption = Program.totalSize - Program.sizeAddedWithEncryption; stopwatch.Stop(); TimeSpan elapsed = stopwatch.Elapsed; string time = string.Format("{0:00}:{1:00}:{2:00}.{3:00}", new object[4] { (object)elapsed.Hours, (object)elapsed.Minutes, (object)elapsed.Seconds, (object)(elapsed.Milliseconds / 10) }); Program.displayStats(time); Program.writeStatsToLog(time); } if (args[0] == "-e") { Program.privkey = Program.findKey(); File.AppendAllText(Program.logPath, Environment.NewLine + "---------------------------------------" + Environment.NewLine); Program.decOnly(args[1]); Console.WriteLine("\n-- Done --"); Program.sizeBeforeEncryption = Program.totalSize - Program.sizeAddedWithEncryption; stopwatch.Stop(); TimeSpan elapsed = stopwatch.Elapsed; string time = string.Format("{0:00}:{1:00}:{2:00}.{3:00}", new object[4] { (object)elapsed.Hours, (object)elapsed.Minutes, (object)elapsed.Seconds, (object)(elapsed.Milliseconds / 10) }); Program.displayStats(time); Program.writeStatsToLog(time); } if (args[0] == "-c") { Console.WriteLine("Counting Files"); Program.countFiles(args[1]); stopwatch.Stop(); TimeSpan elapsed = stopwatch.Elapsed; string time = string.Format("{0:00}:{1:00}:{2:00}.{3:00}", new object[4] { (object)elapsed.Hours, (object)elapsed.Minutes, (object)elapsed.Seconds, (object)(elapsed.Milliseconds / 10) }); Program.displayStats(time); Program.writeStatsToLog(time); Console.WriteLine("Runtime : {0}", (object)time); } if (args[0] == "-j") { Console.WriteLine("Here"); Program.findKey(); } }