public void SetUp()
        {
            EmployeeModel fakeModel = new EmployeeModel
            {
                Id           = 2,
                Email        = "*****@*****.**",
                Type         = EmployeeType.HR,
                PasswordHash = new byte[] { 0, 1, 2 }
            };
            Mock <IEmployeeRepository> employeeRepository = new Mock <IEmployeeRepository>();

            employeeRepository.Setup(c => c.GetEmployeeByLoginPassword(It.IsAny <string>(), It.IsAny <byte[]>())).Returns(fakeModel);
            employeeRepository.Setup(c => c.GetEmployee(It.IsAny <int>())).Returns(fakeModel);

            _employeeRepository = employeeRepository.Object;

            Mock <IFormsAuthenticationService> formsAuthenticationService = new Mock <IFormsAuthenticationService>();

            formsAuthenticationService.Setup(c => c.Login(It.IsAny <string>()));
            formsAuthenticationService.Setup(c => c.Logout());

            _formsAuthenticationService = formsAuthenticationService.Object;
            _encryptService             = new EncryptService();
            _accountService             = new AccountService(_encryptService, _employeeRepository);
        }
 public UserIdentityService(IMapper mapper, IUserRepository userRepository, IJwtService jwtService, IEncryptService encryptService)
 {
     _mapper         = mapper;
     _userRepository = userRepository;
     _jwtService     = jwtService;
     _encryptService = encryptService;
 }
 public AccountService(MiniCloudContext dbContext, IEncryptService encryptService, IDirectoryService directoryService, IResourceAccessService resourceAccessService)
 {
     _dbContext             = dbContext;
     _encryptService        = encryptService;
     _directoryService      = directoryService;
     _resourceAccessService = resourceAccessService;
 }
Example #4
0
        public async Task UpdateEncryptData(IEncryptService srv)
        {
            var keys      = new List <KeyModel>();
            var keyGroups = new List <KeyGroupModel>();
            await DataStoreService.QueryAsync(ctx =>
            {
                foreach (var item in ctx.Set <KeyModel>())
                {
                    var r = item.Decrypt(EncryptService);
                    if (r != null)
                    {
                        keys.Add(r);
                    }
                }
                foreach (var item in ctx.Set <KeyGroupModel>())
                {
                    var r = item.Decrypt(EncryptService);
                    if (r != null)
                    {
                        keyGroups.Add(r);
                    }
                }
            });

            await DataStoreService.SaveAsync(ctx =>
            {
                keys.ForEach(i => ctx.Update(i.Encrypt(srv)));
                keyGroups.ForEach(i => ctx.Update(i.Encrypt(srv)));
            });

            EncryptService = srv;
        }
Example #5
0
 public UserService(IRepository <ForumMembers> members, IRepository <ForumRoles> roles, IRepository <Titles> titles, IRepository <MemberTitle> memberTitle, IEncryptService encrypt)
 {
     _members     = members;
     _roles       = roles;
     _titles      = titles;
     _memberTitle = memberTitle;
     _encrypt     = encrypt;
 }
Example #6
0
 /// <summary>
 ///
 /// </summary>
 public UserController(IEncryptService encryptService, IUserService userService, AppSettings appSettings, IValidationComponent validationComponent, IMapper mapper)
 {
     _encryptService      = encryptService;
     _userService         = userService;
     _appSettings         = appSettings;
     _validationComponent = validationComponent;
     _mapper = mapper;
 }
 public UserQueryService(IDemoRepository repository,
                         IEncryptService encryptService,
                         DemoDbContext dbContext)
     : base(repository)
 {
     _encryptService = encryptService;
     _dbContext      = dbContext;
 }
Example #8
0
 public JwtHelperService(IConfiguration configuration, IRepository <ForumMembers> members, IRepository <Posts> posts, IRepository <ForumRoles> ForumRoles, IEncryptService encrypt)
 {
     _configuration = configuration;
     _members       = members;
     _posts         = posts;
     _forumRole     = ForumRoles;
     _encrypt       = encrypt;
 }
Example #9
0
 public HomeController(ILogger <HomeController> logger, IUserService userService, IRoomService roomservice, IEncryptService encryptService, IMapper mapper)
 {
     _logger         = logger;
     _userService    = userService;
     _roomservice    = roomservice;
     _encryptService = encryptService;
     _mapper         = mapper;
 }
        public static T EncryptPrivateFields <T>(T responseData, IEncryptService encryptService)
        {
            void EncryptPrivateProperty(object data)
            {
                if (data == null)
                {
                    return;
                }

                if (TryIsList(data.GetType()))
                {
                    ((IEnumerable)data).Cast <object>().ToList().ForEach(obj =>
                    {
                        EncryptPrivateProperty(obj);
                    });
                    return;
                }

                var props = data.GetType().GetProperties(BindingFlags.Public | BindingFlags.Instance).ToList();

                foreach (var propInfo in props)
                {
                    var propInfoType = propInfo.PropertyType;
                    if (propInfoType.IsClass && propInfoType.IsGenericType)
                    {
                        TryListOfWhat(propInfoType, out Type subClassType);
                        if (subClassType != null)
                        {
                            ((IEnumerable)propInfo.GetValue(data)).Cast <object>().ToList().ForEach(obj =>
                            {
                                EncryptPrivateProperty(obj);
                            });
                        }
                        continue;
                    }
                    else if (propInfoType.IsClass && propInfoType.Namespace.StartsWith(Assembly.GetExecutingAssembly().GetName().Name))                     // custom class
                    {
                        EncryptPrivateProperty(propInfo.GetValue(data));
                        continue;
                    }

                    var encryptedDataAttribute = propInfo.GetCustomAttribute <EncryptedDataAttribute>(true);
                    if (encryptedDataAttribute != null)
                    {
                        var propValue = propInfo.GetValue(data);
                        if (propValue != null)
                        {
                            propInfo.SetValue(data, null);
                            props.FirstOrDefault(x => x.PropertyType == typeof(string) && x.Name == encryptedDataAttribute.PropertyName)?.SetValue(data, encryptService.Encrypt(propValue.ToString()));
                        }
                    }
                }
            }

            if (responseData == null)
            {
                return(default);
Example #11
0
 public WidgetBasePartService(IEncryptService encryptService, IDataArchivedService dataArchivedService,
                              IApplicationContext applicationContext, IWidgetActivator widgetActivator, IServiceProvider serviceProvider)
     : base(applicationContext)
 {
     EncryptService      = encryptService;
     DataArchivedService = dataArchivedService;
     _widgetActivator    = widgetActivator;
     _serviceProvider    = serviceProvider;
 }
Example #12
0
 /// <summary>
 ///
 /// </summary>
 public UserService(IRedisCache redisCache, IUserRepository userRepository, IUnitOfWork unitOfWork, IEncryptService encryptService, IExternalClient externalClient, IOperatorLogRepository operatorLogRepository)
 {
     _redisCache            = redisCache;
     _userRepository        = userRepository;
     _unitOfWork            = unitOfWork;
     _encryptService        = encryptService;
     _externalClient        = externalClient;
     _operatorLogRepository = operatorLogRepository;
 }
 public AdminController(IAdminService AdminService, MarketplaceDB context, IEncryptService encryptService, IJWTService jwtservice, IConfiguration config, IMailService mailService)
 {
     _AdminService   = AdminService;
     _context        = context;
     _encryptService = encryptService;
     _jwtService     = jwtservice;
     _config         = config;
     _mailService    = mailService;
 }
        public EnctyptVM(IEncryptService encryptService)
        {
            _encryptService     = encryptService;
            RandomSecretCommand = new Command(() =>
            {
                rdStr      = new GetRandomStr();
                SecretText = rdStr.GetRandoms();
            });
            EncryptCommand = new Command(async() =>
            {
                if (await SetKeyTextInputErrorToast())
                {
                    return;
                }
                ResultText = _encryptService.Encrypt(KeyText, SecretText);
            });
            DecryptCommand = new Command(async() =>
            {
                if (await SetKeyTextInputErrorToast())
                {
                    return;
                }
                try
                {
                    ResultText = _encryptService.Decrypt(KeyText, SecretText);
                }
                catch (Exception ex)
                {
                    await App.Current.MainPage.DisplayAlert("错误!", ex.Message, "OK");
                }
            });
            ToClipboardCommand = new Command(async() =>
            {
                if (string.IsNullOrEmpty(ResultText))
                {
                    return;
                }
                await Clipboard.SetTextAsync(ResultText);
            });
            async Task <bool> SetKeyTextInputErrorToast()
            {
                if (string.IsNullOrEmpty(SecretText) || SecretText.Length != 4)
                {
                    await App.Current.MainPage.DisplayAlert("提醒", "特定字符不能为空且长度必须为4!", "好的");

                    return(true);
                }
                if (string.IsNullOrEmpty(KeyText))
                {
                    await App.Current.MainPage.DisplayAlert("提醒", "待加密内容不能为空!", "好的");

                    return(true);
                }
                return(false);
            }
        }
 public LogSignUpController(ISellerService sellerService, IEncryptService encryptService, IConfiguration config, IJWTService jwtservice, MarketplaceDB db, IMailService mailService, IImageService imageService)
 {
     _config         = config;
     _jwtService     = jwtservice;
     _db             = db;
     _mailService    = mailService;
     _iimageService  = imageService;
     _sellerService  = sellerService;
     _encryptService = encryptService;
 }
Example #16
0
 public KeyGroupModel Encrypt(IEncryptService encryptor)
 {
     return(new()
     {
         Id = Id,
         Name = encryptor.Encrypt(Name),
         CreateAt = CreateAt,
         UpdateAt = UpdateAt
     });
 }
Example #17
0
 public AccountService(
     IRepository <User> userRepository,
     IEncryptService encryptService,
     ITokenService tokenService,
     IAuthService authService)
 {
     _userRepository = userRepository;
     _encryptService = encryptService;
     _tokenService   = tokenService;
     _authService    = authService;
 }
Example #18
0
 public ApplicationController(UserManager <User> userManager, IHubContext <NotificationHub> hubContext, IEmailService emailService, IApplicationService applicationService, IApplicationViewModelMapper applicationViewModelMapper, ICheckEgnService checkEgnService, IcheckCardIdService icheckCardId, ICheckPhoneNumberService checkPhoneNumber, IEncryptService encryptService)
 {
     this.hubContext                 = hubContext;
     this.userManager                = userManager;
     this.emailService               = emailService;
     this.applicationService         = applicationService;
     this.applicationViewModelMapper = applicationViewModelMapper;
     this.checkEgnService            = checkEgnService;
     this.checkCardIdService         = icheckCardId;
     this.checkPhoneNumberService    = checkPhoneNumber;
     this.encryptService             = encryptService;
 }
Example #19
0
 public EmailService(TBIAppDbContext dbcontext,
                     IEmailDTOMapper emailDTOMapper,
                     IDecodeService decodeService,
                     ILogger <EmailService> logger,
                     UserManager <User> userManager,
                     IEncryptService encryptService)
 {
     this.dbcontext      = dbcontext ?? throw new ArgumentNullException(nameof(dbcontext));
     this.emailDTOMapper = emailDTOMapper ?? throw new ArgumentNullException(nameof(emailDTOMapper));
     this.decodeService  = decodeService ?? throw new ArgumentNullException(nameof(decodeService));
     this.logger         = logger ?? throw new ArgumentNullException(nameof(logger));
     this.userManager    = userManager;
     this.encryptService = encryptService ?? throw new ArgumentNullException(nameof(encryptService));
 }
Example #20
0
        private ActMgr()
        {
            _aes = new AES256Service()
            {
                Key = Encoding.Default.GetBytes("Yokeqi.AMEasy.AccountManager.AES256.Key").Take(32).ToArray(),
                IV  = Encoding.Default.GetBytes("Yokeqi.AMEasy.AccountManager.AES256.IV").Take(16).ToArray()
            };

            try
            {
                if (File.Exists(C_DATA_PATH))
                {
                    var buff = File.ReadAllBytes(C_DATA_PATH);
                    _data = JObject.Parse(Decrypt(buff));
                    return;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("数据文件解析失败!\r\n" + ex.ToString());
                Application.Exit();
            }

            _data                = new JObject();
            _data["ver"]         = Application.ProductVersion;
            _data["key"]         = Guid.NewGuid().ToString();
            _data["modify_date"] = _data["create_date"] = DateTime.Now.ToString();

            var user = new JObject();

            user["name"]  = "admin";
            user["pass"]  = GeneratePassword("admin", C_SALT, "123456");
            user["tips"]  = "123456";
            _data["user"] = user;

            var accts = new JArray();
            var acct  = new JObject();

            acct["Title"]        = "Demo";
            acct["CategoryName"] = "Demo";
            acct["UserName"]     = "******";
            acct["Password"]     = "******";
            acct["Link"]         = "http://soye360.com";
            acct["Remark"]       = "这是一条示例。\r\n按Ctrl+Enter可以换行。";
            accts.Add(acct);
            _data["data_list"] = accts;

            InnerSave();
        }
Example #21
0
        /// <summary>
        /// Creating register service
        /// </summary>
        /// <param name="unitOfWork">Unit of work of all repositories</param>
        /// <param name="encryptService">Service which encrypt data</param>
        public RegisterService(IUnitOfWork unitOfWork, IEncryptService encryptService)
        {
            if (unitOfWork == null)
            {
                throw new ArgumentNullException(nameof(unitOfWork), " was null.");
            }

            if (encryptService == null)
            {
                throw new ArgumentNullException(nameof(encryptService), " was null.");
            }

            _unitOfWork     = unitOfWork;
            _encryptService = encryptService;
        }
Example #22
0
        public KeyGroupModel?Decrypt(IEncryptService encryptor)
        {
            var name = encryptor.Decrypt(Name);

            if (name is null)
            {
                return(null);
            }
            return(new KeyGroupModel()
            {
                Id = Id,
                Name = name,
                CreateAt = CreateAt,
                UpdateAt = UpdateAt
            });
        }
Example #23
0
 public AccountController(
     UserManager <ApplicationUser> userManager,
     IJwtService jwtService,
     IGenerateResreshTokenService generateResreshTokenService,
     IDecryptService decryptService,
     IEncryptService encryptService,
     ISendEmailService sendEmailService, RoleManager <ApplicationRole> roleManager)
 {
     this.userManager = userManager;
     this.jwtService  = jwtService;
     this.generateResreshTokenService = generateResreshTokenService;
     this.decryptService   = decryptService;
     this.encryptService   = encryptService;
     this.sendEmailService = sendEmailService;
     this.roleManager      = roleManager;
 }
Example #24
0
 public KeyModel Encrypt(IEncryptService encryptor)
 {
     return(new()
     {
         Id = Id,
         Name = encryptor.Encrypt(Name),
         Account = encryptor.Encrypt(Account),
         Password = encryptor.Encrypt(Password),
         SubAccount = encryptor.Encrypt(SubAccount),
         SubPassword = encryptor.Encrypt(SubPassword),
         URL = encryptor.Encrypt(URL),
         Note = encryptor.Encrypt(Note),
         KeyGroup = KeyGroup,
         CreateAt = CreateAt,
         UpdateAt = UpdateAt
     });
 }
Example #25
0
        public KeyModel?Decrypt(IEncryptService encryptor)
        {
            var name = encryptor.Decrypt(Name);

            if (name is null)
            {
                return(null);
            }
            return(new KeyModel()
            {
                Id = Id,
                Name = name,
                Account = encryptor.Decrypt(Account) ?? "",
                Password = encryptor.Decrypt(Password) ?? "",
                SubAccount = encryptor.Decrypt(SubAccount) ?? "",
                SubPassword = encryptor.Decrypt(SubPassword) ?? "",
                URL = encryptor.Decrypt(URL) ?? "",
                Note = encryptor.Decrypt(Note) ?? "",
                KeyGroup = KeyGroup,
                CreateAt = CreateAt,
                UpdateAt = UpdateAt
            });
        }
Example #26
0
 public TextFileReaderService(IEncryptService encryptService)
 {
     _encryptService = encryptService;
 }
Example #27
0
 public ConfigService(IConfiguration configuration)
 {
     this.configuration = configuration;
     _encryptService    = new EncryptionService(configuration);
 }
Example #28
0
 public LoginController(IUserService userService, IEncryptService encryptService)
 {
     _userService    = userService;
     _encryptService = encryptService;
 }
Example #29
0
 public WidgetBasePartService(IEncryptService encryptService, IDataArchivedService dataArchivedService, IApplicationContext applicationContext)
     : base(applicationContext)
 {
     EncryptService      = encryptService;
     DataArchivedService = dataArchivedService;
 }
 public LoginOperation(IEncryptService encryptService, IFileOperation fileOperation)
 {
     this.encryptService = encryptService;
     this.fileOperation  = fileOperation;
 }