示例#1
0
        private void initCipherInput()
        {
            long inputLength;

            using (CStreamReader reader = CipherInput.CreateReader())
            {
                inputLength = reader.Length;

                reader.Read(prelBlock);
                reader.Read(cipherBlock);

                reader.Close();
            }

            for (int byteCounter = 0; byteCounter < blockSize; byteCounter++)
            {
                corruptedBlock[byteCounter] = prelBlock[byteCounter];
            }

            if (inputLength < 2 * blockSize)
            {
                curState = STATES.ERROR;
                GuiLogMessage("Input Message too short. Please check if the Block Size is correct (in the Plugin Settings).", NotificationLevel.Error);
            }
            else if (inputLength > 2 * blockSize)
            {
                GuiLogMessage("The input message is longer than the expected length. Please check if the Block Size is correct (in the Plugin Settings).", NotificationLevel.Warning);
            }
        }
示例#2
0
        public static byte[] StreamToByteArray(ICrypToolStream stream)
        {
            byte[] buf = new byte[stream.Length];

            CStreamReader reader = stream.CreateReader();

            reader.WaitEof();
            reader.Seek(0, System.IO.SeekOrigin.Begin);
            reader.ReadFully(buf);
            reader.Close();

            return(buf);
        }
示例#3
0
        private byte[] ConvertStreamToByteArray(ICryptoolStream stream)
        {
            CStreamReader reader = stream.CreateReader();

            reader.WaitEof(); // does not support chunked streaming

            if (reader.Length > settings.MaxLength)
            {
                AddMessage("WARNING - Stream is too large (" + (reader.Length / 1024).ToString("0.00") + " kB), output will be truncated to " + (settings.MaxLength / 1024).ToString("0.00") + "kB", NotificationLevel.Warning);
            }

            byte[] byteArray = new byte[Math.Min(settings.MaxLength, reader.Length)];
            reader.Seek(0, SeekOrigin.Begin);
            reader.ReadFully(byteArray, 0, byteArray.Length);
            reader.Close();

            return(byteArray);
        }
        public void Dispose()
        {
            if (sr != null)
            {
                sr.Close();
                sr = null;

                sys.Dispose();
                sys = null;

                ids.Dispose();
                ids = null;

                line = 0;
                row  = 0;

                current = null;
                handler = null;
                typeMap = null;
            }
            GC.SuppressFinalize(this);
        }
示例#5
0
        public void Execute()
        {
            //GuiLogMessage("PO exec", NotificationLevel.Info);

            errorCode = 0;

            try
            {
                ProgressChanged(0, 1);
                using (CStreamReader reader = DecryptedInputStream.CreateReader())
                {
                    errorCode = 1;

                    blockSize = System.Convert.ToInt16(reader.Length / 2);

                    plainBlock = new byte[blockSize];

                    errorCode = 2;

                    //read input
                    reader.Read(plainBlock); //first block -> ignore
                    reader.Read(plainBlock);
                    reader.Close();
                }

                errorCode = 3;

                bool   validPadding = true;
                byte[] result       = new byte[1];

                //expected padding length = value of last byte
                paddingLength = System.Convert.ToInt16(plainBlock[blockSize - 1]);
                if (paddingLength == 0 || paddingLength > blockSize) //check if paddingLen is invalid
                {
                    validPadding = false;
                }
                else //padding length is valid
                {
                    //go through all supposed padding bytes and check if they all have the correct value
                    int wordCounter = 1;
                    while (validPadding && wordCounter < paddingLength)
                    {
                        if (plainBlock[blockSize - 1 - wordCounter] != paddingLength)
                        {
                            validPadding = false;
                        }
                        wordCounter++;
                    }
                }

                errorCode = 4;

                //Update Presentation Layer
                plainBlockStr = System.BitConverter.ToString(plainBlock);
                plainBlockStr = plainBlockStr.Replace("-", " ");
                errorCode     = 6;
                setPadPointer();
                errorCode = 7;
                setContent();
                errorCode = 85;
                errorCode = 9;

                double minVal = Math.Min(18 - blockSize, 10);
                minVal /= 10;


                Presentation.Dispatcher.Invoke(DispatcherPriority.Normal, (SendOrPostCallback) delegate
                {
                    pres.showPaddingImg(validPadding);
                    pres.viewByteScroller.Minimum = minVal;
                }, null);

                isInitiated = true;

                PaddingResult = validPadding;
                OnPropertyChanged("PaddingResult");
            }
            catch (System.Exception e)
            {
                GuiLogMessage("PO error: " + errorCode, NotificationLevel.Error);
            }


            ProgressChanged(1, 1);
        }