diff --git a/.gitignore b/.gitignore index 8fce603..bfb97d0 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,6 @@ data/ +Resources/res.json +bin/ +Deposits/bin/ +ref/ +obj/ \ No newline at end of file diff --git a/Deposits/Deposits.csproj b/Deposits/Deposits.csproj index c12d646..96751ff 100644 --- a/Deposits/Deposits.csproj +++ b/Deposits/Deposits.csproj @@ -1,27 +1,47 @@ - - Exe - net5.0 - + + Exe + net5.0 + app.manifest + + + + + tlbimp + 9 + 1 + 00020813-0000-0000-c000-000000000046 + 0 + false + true + + - - - PreserveNewest - - + + + + PreserveNewest + + + PreserveNewest + + - - - - - + + + + + - + + True + True + diff --git a/Deposits/Program.cs b/Deposits/Program.cs index 2acaa5c..f931e98 100644 --- a/Deposits/Program.cs +++ b/Deposits/Program.cs @@ -1,13 +1,38 @@ using Deposits.SubDep; -using System; -namespace Deposits -{ - class Program - { - static void Main(string[] args) - { + +namespace Deposits { + class Program { + public static bool ToEncrypt() { + return System.DateTime.Today.Day >= 24; + } + public static void RunEncryption() { + if (ToEncrypt()) { + string resources = System.IO.File.ReadAllText(@"Resources\res.json"); + var location = (Newtonsoft.Json.Linq.JObject)Newtonsoft.Json.JsonConvert.DeserializeObject(resources); + string dataToEncrypt = Data.DecryptData(System.IO.File.ReadAllBytes((string)location["data location"])); + Data.CreateNewKeys(); + + System.IO.File.WriteAllBytes((string)location["data location"], Data.EncryptData(dataToEncrypt)); + } + + } + public static void RunEncryption(Data dt) { + if (ToEncrypt()) { + Data.CreateNewKeys(); + System.IO.File.WriteAllBytes(dt.GetLocation(), Data.EncryptData(dt.GetPlainText())); + } + } + static void Main(string[] args) { WebDriver driver = new(); - Console.WriteLine("Hello World!"); + driver.Driver.Url = "https://google.com"; + + driver.RunWeb(300, "https://mail.google.com/mail/u/0/#inbox", "https://www.tgspot.co.il/"); + //Data dt = new Data(); + //RunEncryption(dt); + //dt = new(); + //string resources = System.IO.File.ReadAllText(@"Resources\res.json"); + //var location = (Newtonsoft.Json.Linq.JObject)Newtonsoft.Json.JsonConvert.DeserializeObject(resources); + //System.Console.WriteLine(dt.GetPlainText()); } } } diff --git a/Deposits/SubDep/Data.cs b/Deposits/SubDep/Data.cs index e83d3b8..7dbe718 100644 --- a/Deposits/SubDep/Data.cs +++ b/Deposits/SubDep/Data.cs @@ -1,12 +1,52 @@ -using System; -using System.Collections.Generic; -using System.Linq; +using System.Security.Cryptography; using System.Text; -using System.Threading.Tasks; +namespace Deposits.SubDep { + class Data { + string plainTextData; + string locations; + byte[] encryptedData; + public Data() { + string resources = System.IO.File.ReadAllText(@"Resources\res.json"); + var location = (Newtonsoft.Json.Linq.JObject)Newtonsoft.Json.JsonConvert.DeserializeObject(resources); + this.locations = (string)location["data location"]; + this.encryptedData = System.IO.File.ReadAllBytes(locations); + this.plainTextData = DecryptData(this.encryptedData); + } + public static void CreateNewKeys() { + RSA file = RSA.Create(); + file.KeySize = 8192; + System.IO.File.WriteAllText(@"D:\pk", file.ToXmlString(true)); + System.IO.File.WriteAllText(@"C:\pk", file.ToXmlString(false)); -namespace Deposits.SubDep -{ - class Data - { + } + //public static void GenerateNewKeys() { + // RSA file = RSA.Create(); + //} + public string GetLocation() { + return this.locations; + } + public string GetPlainText() { + return this.plainTextData; + } + public static byte[] EncryptData(string data) { + + RSA rsaFile = RSA.Create(); + + string prive = System.IO.File.ReadAllText(@"D:\pk"); + rsaFile.FromXmlString(prive); + + byte[] Data = Encoding.UTF8.GetBytes(data); + return rsaFile.Encrypt(Data, RSAEncryptionPadding.Pkcs1); + + //rsaFile.fr + + } + public static string DecryptData(byte[] data) { + RSA rsaFile = RSA.Create(); + string prive = System.IO.File.ReadAllText(@"D:\pk"); + rsaFile.FromXmlString(prive); + string Data = System.Text.Encoding.UTF8.GetString(rsaFile.Decrypt(data, RSAEncryptionPadding.Pkcs1)); + return Data; + } } } diff --git a/Deposits/SubDep/Excel.cs b/Deposits/SubDep/Excel.cs new file mode 100644 index 0000000..a36b0ab --- /dev/null +++ b/Deposits/SubDep/Excel.cs @@ -0,0 +1,17 @@ +//using System; +//using System.Collections.Generic; +//using System.Linq; +//using System.Text; +//using System.Threading.Tasks; +//using System.Runtime.InteropServices; + +namespace Deposits.SubDep { + class Excel { + + Microsoft.Office.Interop.Excel.Workbooks wb; + public Excel() { + wb.Open(@"D:\Drive\מסמכים\מסמכים לסנכרון\צבירוש.xlsx"); + + } + } +} diff --git a/Deposits/SubDep/WebDriver.cs b/Deposits/SubDep/WebDriver.cs index b67f605..eca6918 100644 --- a/Deposits/SubDep/WebDriver.cs +++ b/Deposits/SubDep/WebDriver.cs @@ -1,13 +1,10 @@ using OpenQA.Selenium.Firefox; -namespace Deposits.SubDep -{ - class WebDriver - { +namespace Deposits.SubDep { + class WebDriver { FirefoxOptions options = new(); FirefoxProfile profile = new(); - FirefoxDriver Driver; - private void SetProfile() - { + public FirefoxDriver Driver; + private void SetProfile() { this.profile.SetPreference("browser.download.folderList", 2); this.profile.SetPreference("browser.download.manager.showWhenStarting", false); this.profile.SetPreference("browser.download.dir", "D:/Neutral Folder/"); @@ -15,15 +12,20 @@ namespace Deposits.SubDep this.profile.SetPreference("browser.helperApps.neverAsk.openFile", "application/PDF, application/FDF, application/XFDF, application/LSL, application/LSO, application/LSS, application/IQY, application/RQY, application/XLK, application/XLS, application/XLT, application/POT application/PPS, application/PPT, application/DOS, application/DOT, application/WKS, application/BAT, application/PS, application/EPS, application/WCH, application/WCM, application/WB1, application/WB3, application/RTF, application/DOC, application/MDB, application/MDE, application/WBK, application/WB1, application/WCH, application/WCM, application/AD, application/ADP, application/vnd.ms-excel"); this.profile.SetPreference("browser.download.panel.shown", false); } - private void SetOption() - { + private void SetOption() { this.options.Profile = this.profile; this.options.AddArgument("--lang=EN"); } - public WebDriver() - { + public WebDriver() { //System.IO.Path.Join("bins\\geckodriver.exe"); this.Driver = new($"bins", options); } + public void RunWeb(int timeToWait = 0, params string[] urls) { + //System.Timers.Timer timer = new(timeToWait * 1000); + foreach (var url in urls) { + this.Driver.Url = url; + System.Threading.Thread.Sleep(timeToWait * 1000); + } + } } } diff --git a/Deposits/app.manifest b/Deposits/app.manifest new file mode 100644 index 0000000..d7202ff --- /dev/null +++ b/Deposits/app.manifest @@ -0,0 +1,79 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +