Пример #1
0
        public bool encryptrsa(string source, string destination, string key_friend)
        {
            RSA encryptor       = new RSA();
            RSA friendEncryptor = new RSA();

            if (key_friend.Equals(""))
            {
                encryptor.SetPubKey(user_public_key);
            }
            else
            {
                encryptor.SetPubKey(user_private_key);
                friendEncryptor.SetPubKey(key_friend);
            }


            inputHasher  = new hasher();
            outputHasher = new hasher();


            FileInfo info = new FileInfo(source);

            input  = new FileIO(source);
            output = new FileIO(destination);

            output.Open_Writer();
            output.Write_line(info.Name);
            output.Write_line("CODE:");

            int count;

            byte[] hulp;

            input.OpenRead();

            while ((count = input.Read_part()) > 0)
            {
                inputHasher.Add_part(input.buffer);
                hulp = encryptor.run_encrypt(input.buffer);

                if (!key_friend.Equals(""))
                {
                    //hulp = friendEncryptor.run_encrypt(hulp);

                    outputHasher.Add_part(hulp);
                }
                output.Write_line(hulp);
            }


            input.close_file();

            writeEnd();
            output.Writer_close();

            return(true);
        }
Пример #2
0
        public void Add_user(string name, string password)
        {
            hashing = new hasher();

            password = hashing.Hash_met_salt(Transformer.GetByteValue(password));

            RSA rsaencryptor = new RSA();

            rsaencryptor.generateNewKeyPair();
            bestand.Add_User(name, password, rsaencryptor.privKey, rsaencryptor.pubKey);
        }
Пример #3
0
        public bool encryptSym(string source, string destination)
        {
            AesEncryptie symEncryptor = new AesEncryptie();

            inputHasher  = new hasher();
            outputHasher = new hasher();


            FileInfo info = new FileInfo(source);

            input  = new FileIO(source);
            output = new FileIO(destination);

            try {
                writeBegin(info.Name, program_encryptor.run_encrypt(symEncryptor.KEY), program_encryptor.run_encrypt(symEncryptor.IV));
            }
            catch (FileNotFoundException ex)
            {
                throw new Exceptions("File not found:" + ex.FileName, "Encryptie");
            }
            catch (FileLoadException ex)
            {
                throw new Exceptions("Geen toegangsrechten:" + ex.FileName, "Encryptie");
            }


            int count;

            byte[] hulp;

            input.OpenRead();

            while ((count = input.Read_part()) > 0)
            {
                inputHasher.Add_part(input.buffer);
                hulp = symEncryptor.encrypt(input.buffer);
                outputHasher.Add_part(hulp);
                output.Write_line(hulp);
            }
            symEncryptor.end_encryption();
            input.close_file();

            writeEnd();
            output.Writer_close();
            return(true);
        }
Пример #4
0
        public bool checkLogin(string naam, string wachtwoord)
        {
            hashing = new hasher();
            List <string> userValues = get_user(naam);

            if (userValues == null)
            {
                return(false);
            }


            if (!hashing.check_hash(Transformer.GetByteValue(wachtwoord), userValues[0]))
            {
                return(false);
            }

            username         = naam;
            user_private_key = userValues[1];
            user_public_key  = userValues[2];

            return(true);
        }
Пример #5
0
        public bool decryptrsa(string source, string destination, string key_friend)
        {
            RSA encryptor       = new RSA();
            RSA friendEncryptor = new RSA();


            encryptor.SetPrivKey(user_private_key);

            if (!key_friend.Equals(""))
            {
                friendEncryptor.SetPrivKey(key_friend);
            }

            inputHasher  = new hasher();
            outputHasher = new hasher();

            input = new FileIO(source);

            input.Open_Reader();
            string filename = input.read_till("CODE:");

            FileInfo info            = new FileInfo(filename);
            FileInfo infoDestination = new FileInfo(destination);

            if (!infoDestination.Extension.Equals(info.Extension))
            {
                output = new FileIO(destination, info.Extension);
            }
            else
            {
                output = new FileIO(destination);
            }

            byte[] hulp;

            output.OpenWrite();

            while (input.readCode() > 0)
            {
                inputHasher.Add_part(input.buffer);

                if (!key_friend.Equals(""))
                {
                    hulp = friendEncryptor.run_decrypt(input.buffer);
                    hulp = encryptor.run_decrypt(hulp);
                }
                else
                {
                    hulp = encryptor.run_decrypt(input.buffer);
                }

                outputHasher.Add_part(hulp);
                output.Write_part(hulp);
            }

            Check_Hashes();

            output.close_file();

            return(true);
        }
Пример #6
0
        public bool decryptSym(string source, string destination)
        {
            AesEncryptie symEncryptor;

            inputHasher  = new hasher();
            outputHasher = new hasher();

            string filename = "";

            byte[] key = new byte[0];
            byte[] IV  = new byte[0];

            input = new FileIO(source);

            try
            {
                ReadBegin(ref filename, ref key, ref IV);
            }
            catch (Exceptions ex)
            {
                throw new Exceptions("Wegschrijven lukte niet:" + ex.Message, "Decryptie");
            }

            try
            {
                FileInfo info            = new FileInfo(filename);
                FileInfo infoDestination = new FileInfo(destination);
                if (!infoDestination.Extension.Equals(info.Extension))
                {
                    output = new FileIO(destination, info.Extension);
                }
                else
                {
                    output = new FileIO(destination);
                }

                symEncryptor = new AesEncryptie(program_encryptor.run_decrypt(IV), program_encryptor.run_decrypt(key));


                byte[] hulp;

                output.OpenWrite();

                while (input.readCode() > 0)
                {
                    inputHasher.Add_part(input.buffer);
                    hulp = symEncryptor.encrypt(input.buffer);

                    outputHasher.Add_part(hulp);
                    output.Write_part(hulp);
                }

                symEncryptor.end_encryption();
                Check_Hashes();
            }
            catch (Exceptions ex)
            {
                throw new Exceptions("Er is geknoeit met de input files:" + ex.Message, "Decryptie");
            }
            output.close_file();

            return(true);
        }