Пример #1
0
        public static void Signing(File f)
        {
            string filehash = Cryptfunc.GetHash(Cryptfunc.AESDecrypt(System.IO.File.ReadAllBytes(f.pathtofile)));
            string logshash = Cryptfunc.GetHash(Cryptfunc.AESDecrypt(System.IO.File.ReadAllBytes(f.pathtolog)));
            string strout   = filehash + " -- " + logshash;

            System.IO.File.WriteAllBytes(f.pathtosign, Cryptfunc.RSAEncrypt(System.Text.Encoding.Default.GetBytes(strout)));
        }
Пример #2
0
        //get from file
        public File(string dir)
        {
            this.pathtofile = dir;

            while (dir[dir.Length - 1] != '.')
            {
                dir = dir.Remove(dir.Length - 1);
            }
            this.pathtosign = dir + "sig";
            this.pathtolog  = dir + "log";
            dir             = dir.Remove(dir.Length - 1);

            while (dir[dir.Length - 1] != '\\')
            {
                this.name += dir[dir.Length - 1];
                dir        = dir.Remove(dir.Length - 1);
            }
            this.name = new string(this.name.ToCharArray().Reverse().ToArray());

            if (this.IsSigExist())
            {
                string strfromsig = System.Text.Encoding.UTF8.GetString(Cryptfunc.RSADecrypt(System.IO.File.ReadAllBytes(this.pathtosign)));
                int    i          = 0;
                if (strfromsig.Contains(" -- "))
                {
                    while (strfromsig.Substring(i, 4) != " -- ")
                    {
                        this.filehashfromsig += strfromsig[i];
                        i++;
                    }
                    this.loghashfromsig = strfromsig.Remove(0, i + 4);
                }
            }

            this.goodfile = this.IsFileValid() && this.IsLogValid();
            if (this.goodfile)
            {
                string[] sep  = { "\r\n" };
                string   str1 = System.Text.Encoding.UTF8.GetString(Cryptfunc.AESDecrypt(System.IO.File.ReadAllBytes(this.pathtolog)));
                string[] str  = str1.Split(sep, StringSplitOptions.RemoveEmptyEntries);
                logs = new List <Logline>();
                foreach (string s in str)
                {
                    this.logs.Add(new Logline(s));
                }

                int lastlog = logs.Count - 1;
                this.date     = logs[lastlog].date;
                this.note     = logs[lastlog].note;
                this.touser   = logs[lastlog].touser;
                this.fromuser = logs[lastlog].fromuser;
                this.state    = logs[lastlog].state;
            }
        }
Пример #3
0
        private void EditFile_Click(object sender, EventArgs e)
        {
            WordApp = new Word.Application()
            {
                Visible = true
            };
            System.IO.File.WriteAllBytes(file.pathtofile, Cryptfunc.AESDecrypt(System.IO.File.ReadAllBytes(file.pathtofile)));
            object readOnly = false;
            object path     = file.pathtofile;

            WordDoc = WordApp.Documents.Open(ref path, ref miss, ref readOnly, ref miss, ref miss, ref miss, ref miss, ref miss, ref miss, ref miss, ref miss, ref miss, ref miss, ref miss, ref miss, ref miss);
            WordDoc.Activate();

            Controlfunc.Makeitinvisible(EditFile, SeeLogs, Deletefile);
            Controlfunc.Makeitvisible(Chooseuserlabel, Chosenuser, ActionSelectionBox, Actionselectionlabel, NoteBox, Notelabel1, Notelabel2, EndwithoutSave, EndwithSave);
        }
Пример #4
0
        private void Seefile_Click(object sender, EventArgs e)
        {
            WordApp = new Word.Application()
            {
                Visible = true
            };

            compl = Cryptfunc.AESDecrypt(System.IO.File.ReadAllBytes(file.pathtofile));
            System.IO.File.WriteAllBytes(file.pathtofile, compl);
            object readOnly = false;
            object path     = file.pathtofile;

            WordDoc = WordApp.Documents.Open(ref path, ref miss, ref readOnly, ref miss, ref miss, ref miss, ref miss, ref miss, ref miss, ref miss, ref miss, ref miss, ref miss, ref miss, ref miss, ref miss);
            WordDoc.Activate();

            Controlfunc.Makeitinvisible(Seefile, Deletefile);
            see = true;
        }
Пример #5
0
 public bool IsLogValid()
 {
     if (this.IsSigExist() && this.IsLogsExist())
     {
         string filehash = Cryptfunc.GetHash(Cryptfunc.AESDecrypt(System.IO.File.ReadAllBytes(this.pathtolog)));
         if (this.loghashfromsig == filehash)
         {
             return(true);
         }
         else
         {
             return(false);
         }
     }
     else
     {
         return(false);
     }
 }
Пример #6
0
 void Initializeuserbase()
 {
     string[] ch = { "\r\n" };
     string[] s  = System.Text.Encoding.UTF8.GetString(Cryptfunc.AESDecrypt(System.IO.File.ReadAllBytes(pathtobase))).Split(ch, StringSplitOptions.RemoveEmptyEntries);
     foreach (string str in s)
     {
         string uname = "", upass = "";
         int    uaccess;
         int    i = 0;
         while (str[i] != ' ')
         {
             uname += str[i++];
         }
         i++;
         uaccess = int.Parse(str[i].ToString());
         i      += 2;
         while (i < str.Length)
         {
             upass += str[i++];
         }
         userbase.Add(new User(uname, uaccess, upass));
     }
 }
Пример #7
0
        public static void Loging(File f)
        {
            byte[] logs;
            if (f.IsLogsExist())
            {
                logs = Cryptfunc.AESDecrypt(System.IO.File.ReadAllBytes(f.pathtolog));
            }
            else
            {
                logs = null;
            }

            string laststr = f.state + " -- " + f.fromuser + " -- " + f.touser + " -- " + DateTime.Now + " -- " + f.note;

            if (logs != null)
            {
                string slogs = System.Text.Encoding.UTF8.GetString(logs);
                System.IO.File.WriteAllBytes(f.pathtolog, Cryptfunc.AESEncrypt(System.Text.Encoding.UTF8.GetBytes(slogs + "\r\n" + laststr)));
            }
            else
            {
                System.IO.File.WriteAllBytes(f.pathtolog, Cryptfunc.AESEncrypt(System.Text.Encoding.UTF8.GetBytes(laststr)));
            }
        }