private async void BtnConsumerRequestsHistoryViewGet_Click(object sender, Avalonia.Interactivity.RoutedEventArgs e)
        {
            await Dispatcher.UIThread.InvokeAsync(() =>
            {
                outputText.Text = string.Empty;
                timeText.Text   = string.Empty;
                btnConsumerRequestsHistoryViewGet.IsEnabled = false;
            });

            Stopwatch sw = new Stopwatch();

            hubConnection.On <String>("ConsumerRequestsHistoryViewGet", async(data) =>
            {
                var bytes = System.Convert.FromBase64String(data);
                data      = _dataEncryptor.Decrypt(bytes, clientEncryptorKey);

                sw.Stop();

                await Dispatcher.UIThread.InvokeAsync(() =>
                {
                    outputText.Text = JToken.Parse(data).ToString(Formatting.Indented);
                    timeText.Text   = $"Time: {sw.ElapsedMilliseconds} ms, Host: {url}";
                    btnConsumerRequestsHistoryViewGet.IsEnabled = true;
                });
            });

            sw.Start();

            await hubConnection.InvokeAsync("ConsumerRequestsHistoryViewGet");
        }
        public void Should_ReturnDecryptedText_ForGivenCipher()
        {
            var password = "******";

            var encrypted = _aes256Encryptor.Encrypt(password);;
            var decrypted = _aes256Encryptor.Decrypt(encrypted);;

            Assert.NotNull(decrypted);
            Assert.Equal(password, decrypted);
        }
Пример #3
0
        /// <summary>
        /// Decrypts the cipher data.
        /// </summary>
        /// <param name="encryptor">The data encryptor, cannot be null.</param>
        /// <param name="key">The key of the cipher, it may have been used as extra entropy, cannot be null but can be empty.</param>
        /// <returns>The decrypted data, never but can be empty.</returns>
        /// <exception cref="ArgumentNullException">The key or provider argument is null.</exception>
        /// <exception cref="CryptographicException">The decryption operation failed.</exception>
        /// <remarks>The calling context is responsible for serializing and deserializing data to and from byte[].</remarks>
        public byte[] GetData(IDataEncryptor encryptor, string key)
        {
            if (encryptor == null)
            {
                throw new ArgumentNullException("encryptor");
            }

            if (key == null)
            {
                throw new ArgumentNullException("key");
            }

            return(encryptor.Decrypt(key, this.cipher));
        }
Пример #4
0
        public IEnumerable <FileData> ReadFile(string directoryPath)
        {
            DirectoryInfo directoryInfo = new DirectoryInfo(directoryPath);

            Dictionary <string, string>         dctPermissions = new Dictionary <string, string>();
            Tuple <bool, IEnumerable <string> > roleFeatures   = null;

            if (useRoleBasedSecurity)
            {
                roleFeatures = fileSecurity.GetRoleFeatures(roleName);
                if (!roleFeatures.Item1 && roleFeatures.Item2 != null)
                {
                    roleFeatures.Item2.ToList().ForEach(p => dctPermissions[Path.Combine(directoryInfo.FullName, p)] = null);
                }
            }

            List <FileData> fileDataCollection = new List <FileData>();
            string          fileContent;

            foreach (FileInfo file in directoryInfo.EnumerateFiles("*.txt", SearchOption.AllDirectories))
            {
                if (useRoleBasedSecurity &&
                    !roleFeatures.Item1 &&
                    !dctPermissions.ContainsKey(file.FullName))
                {
                    continue;
                }

                fileContent = File.ReadAllText(file.FullName);
                fileDataCollection.Add(new FileData
                {
                    Name    = file.Name,
                    Content = useEncryptionSystem ? dataEncryptor.Decrypt(fileContent) : fileContent
                });
            }

            return(fileDataCollection);
        }