Example #1
0
        void checkSavedFiles(string MD5)
        {
            byte[] encrypted = File.ReadAllBytes(pathToEncFile);
            byte[] key       = File.ReadAllBytes(pathToKeyFile);

            Brstub br = new Brstub();

            byte[] decrypted = br.Decrypt(encrypted, key);

            if (br.CheckMD5(decrypted, MD5))
            {
                System.Console.WriteLine("Saving data succesfull!");
            }
            else
            {
                tmpStr = br.GetMd5Hash(decrypted);
                ErrorHndlr(Errors.savingFileError);
            }
        }
Example #2
0
        static void Main(string[] args)
        {
            Program brcrypt = new Program();

            //read args
            if (args.Length != 3)
            {
                brcrypt.ErrorHndlr(Errors.tooFewArgs);
            }
            brcrypt.pathToFile    = args[0];
            brcrypt.pathToEncFile = args[1];
            brcrypt.pathToKeyFile = args[2];

            //check file existance
            if (!File.Exists(brcrypt.pathToFile))
            {
                brcrypt.ErrorHndlr(Errors.inputFileDontExist);
            }


            System.Console.WriteLine("Reading file {0}...", brcrypt.pathToFile);
            byte[] inputFile = File.ReadAllBytes(brcrypt.pathToFile); //read file

            Brstub brstub = new Brstub();                             //make object brstub

            System.Console.WriteLine("Genrating MD5 hash...");
            string inputFileMD5 = brstub.GetMd5Hash(inputFile);  //make MD5 hash of inputFile

            //System.Console.WriteLine(inputFileMD5);   //debug

            System.Console.WriteLine("Encoding file {0}...", brcrypt.pathToFile);

            byte[] key       = brstub.GenKey();                //generate key
            byte[] encrypted = brstub.Encrypt(inputFile, key); //encrypted data


            //check encryption

            byte[] decrypted = brstub.Decrypt(encrypted, key);  //decrypted data

            /*tesing line for enc troubles
             * System.Console.WriteLine("Enc:{0}", brstub.GetMd5Hash(encrypted));
             * System.Console.WriteLine("Dec:{0}", brstub.GetMd5Hash(decrypted));
             */


            if (brstub.CheckMD5(decrypted, inputFileMD5))
            {
                System.Console.WriteLine("Encrypted succesfull!");

                System.Console.WriteLine("Saving data to file {0}...", brcrypt.pathToEncFile);
                File.WriteAllBytes(brcrypt.pathToEncFile, encrypted);

                System.Console.WriteLine("Saving key to file {0}...", brcrypt.pathToKeyFile);
                File.WriteAllBytes(brcrypt.pathToKeyFile, key);

                //System.Console.WriteLine("Key:{0}", key);
                System.Console.WriteLine("MD5:{0}", inputFileMD5);


                brcrypt.checkSavedFiles(inputFileMD5);
            }
            else
            {
                brcrypt.ErrorHndlr(Errors.encryptionError);
            }
        }