public static MemoryStream CreateKeyStream(FilePasswordPair key)
        {
            FileStream   fileStream    = new FileStream(key.fileName, FileMode.Open);
            MemoryStream resultStream  = new MemoryStream();
            int          passwordIndex = 0;
            int          currentByte   = 0;

            while ((currentByte = fileStream.ReadByte()) >= 0)
            {
                //combine the key-byte with the corresponding password-byte
                currentByte = currentByte ^ key.password[passwordIndex];

                //add the result to the key stream
                resultStream.WriteByte((byte)currentByte);

                //proceed to the next letter or repeat the password
                passwordIndex++;
                if (passwordIndex == key.password.Length)
                {
                    passwordIndex = 0;
                }
            }

            fileStream.Close();

            resultStream.Seek(0, SeekOrigin.Begin);
            return(resultStream);
        }
        public FilePasswordPair[] GetKeys()
        {
            FilePasswordPair[] result = new FilePasswordPair[lvKeys.Items.Count];
            ListViewItem       item;

            for (int n = 0; n < lvKeys.Items.Count; n++)
            {
                item      = lvKeys.Items[n];
                result[n] = (FilePasswordPair)item.Tag;
            }
            return(result);
        }