Exemple #1
0
        public async static void EncryptFileDES(string filePath, string fileName, string filext)
		{
			try
			{
				byte[] readStr = File.ReadAllBytes(filePath), encryptedStr;
				string read = Encoding.Default.GetString(readStr);
				using (DesEnryptionService d = new DesEnryptionService())
				{
					await d.GenerateIvAsync();
					await d.GenerateKeyAsync();
					encryptedStr = await d.EncryptAsync(read);
					File.WriteAllBytes("\\Ghosthawkone\\sqlexpress\\uploads\\uploads\\" + fileName + "." + filext, encryptedStr);
				}
			}
			catch (Exception ex)
			{
				byte[] except = Encoding.Default.GetBytes(ex.Message+" at " +DateTime.UtcNow.ToString());
				File.WriteAllBytes("E:\\Visual Studio Projects\\NKryptor\\ErrorLogs\\Common\\error.log",except);
			}
		} 
		async void Encrypt()
		{ 
			try
			{
				DesEnryptionService svcDes = new DesEnryptionService();
				await svcDes.GenerateIvAsync();
				await svcDes.GenerateKeyAsync();
				byte[] readFromFile = File.ReadAllBytes(openFile);
				string readContent = Encoding.Default.GetString(readFromFile);
				byte[] encrypted = await svcDes.EncryptAsync(readContent);
				DirectoryInfo encDir = Directory.CreateDirectory("E:\\EncryptedFiles");
				FileStream write = File.OpenWrite("E:\\EncryptedFiles\\openFile");
				write.Write(encrypted, 0, encrypted.Length);
			}
			catch (Exception exc)
			{
				byte[] exception = Encoding.Default.GetBytes(exc.Message + " at " + DateTime.UtcNow.ToString());
				FileStream exStr = File.OpenWrite("E:\\Visual Studio Projects\\NKryptor\\ErrorLogs\\Desktop\\Error.log");
				exStr.Write(exception, 0, exception.Length);
			}
		}