Example #1
0
        public static string DecryptPassword(string password, string odbiorca)
        {
            var data       = FileMy.PobranieDanychZPliku(odbiorca);
            var cryptoData = RC6.OdszyfrowywanieRc6Password(data, password);

            try
            {
                return(Encoding.ASCII.GetString(cryptoData));
            }
            catch (Exception)
            {
                return(null);
            }
        }
Example #2
0
        public static void OdszyfrowywanieRc6(string wejscie, string wyjscie, Odbiorcy odbiorca, NaglowekPliku naglowek, MainWindow window)
        {
            //data
            var reader2 = new StreamReader(wejscie);
            var reader = new FileMy(reader2);
            while (true)
            {
                var searcher = reader.ReadLine();
                if (searcher != null && searcher.StartsWith("</EnctyptedFileHeader>"))
                    break;
            }
            var position = reader.Position;
            reader.Close();
            var entry = new FileStream(wejscie, FileMode.Open)
            {
                Position = position      
            };
            var exit = new System.IO.FileStream(wyjscie, FileMode.Create);



            //decrypt
            var blockCipher = CreateCipher(naglowek.Tryb, naglowek.WielkoscPodBloku);
            ICipherParameters parameters;
            if (naglowek.Tryb == "ECB")
                parameters = new KeyParameter(odbiorca.KluczSesyjny);
            else
                parameters = new ParametersWithIV(new KeyParameter(odbiorca.KluczSesyjny), naglowek.Iv);
            blockCipher.Init(false, parameters);

            //date for progresbar
            long lenghtFile = entry.Length;
            double progres = lenghtFile / 1000;
            long actuallyLenght = 0;

            //date for encrypt
            var buffer = new byte[16];
            var outputBytes = new byte[blockCipher.GetOutputSize(buffer.Length)];
            var length = 0;
            int bytesRead;

             while ((bytesRead = entry.Read(buffer, 0, buffer.Length)) > 0)
            {

                length = blockCipher.ProcessBytes(buffer, 0, bytesRead, outputBytes, 0);
                exit.Write(outputBytes, 0, length);
                //progresbar
                actuallyLenght += bytesRead;
                if (actuallyLenght > progres)
                {
                    window.progressBarOdszyfrowywanie.Dispatcher.Invoke(
                        System.Windows.Threading.DispatcherPriority.Normal,
                        new Action(
                            delegate()
                            {
                                window.progressBarOdszyfrowywanie.Value += 0.1;
                            }
                            ));
                    actuallyLenght -= (long) progres;
                }
            }
            length = blockCipher.DoFinal(outputBytes, 0);
            exit.Write(outputBytes, 0, length);

            entry.Close();
            exit.Close();
        }