Example #1
0
        public async Task SaveProtectedAsync <T>(
            T data,
            string fileName,
            string directory = "",
            CancellationToken cancellationToken = default)
        {
            var jsonData  = JsonSerializer.SerializeToUtf8Bytes(data);
            var encrypted = _userDataProtector.Protect(jsonData);
            var path      = Path.Combine(GetUserDirectory(directory), $"{fileName}");

            await File.WriteAllBytesAsync(path, encrypted, cancellationToken);
        }
        private void ProtectSecrets(ConnectedService connectedService)
        {
            IConnectedServiceProvider provider = _providers
                                                 .First(x => x.Type.Name == connectedService.Type);

            foreach (ConnectedServiceProperty property in connectedService.Properties
                     .Where(x => provider.Type.SecretProperties.Contains(x.Name)))
            {
                if (property.Value is string)
                {
                    property.Value    = _userDataProtector.Protect(property.Value);
                    property.IsSecret = true;
                }
            }
        }