Beispiel #1
0
 public DataProtector(
     IEncryptionFactory encryptionFactory,
     IDataKeyProvider dataKeyProvider)
 {
     _encryptionFactory = encryptionFactory;
     _dataKeyProvider   = dataKeyProvider;
 }
        /// <summary>
        /// Obtiene el proveedor de cifrado solicitado
        /// </summary>
        /// <param name="proveedor">Proveedor de cifrado</param>
        /// <returns></returns>
        public IEncryptionFactory GetProvider(EncryptionProvider proveedor)
        {
            IEncryptionFactory resultado = null;

            switch (proveedor)
            {
            case EncryptionProvider.Aes:
                resultado = new AesEncryptionProvider();
                break;

            case EncryptionProvider.Rsa:
                resultado = new RsaEncryptionProvider();
                break;

            case EncryptionProvider.TripeDes:
                resultado = new TripeDESEncryptionProvider();
                break;

            default:
                throw new NotImplementedException();
            }
            if (resultado == null)
            {
                throw new NotImplementedException();
            }
            return(resultado);
        }
 public CacheDataKeyApplicationKernalService(
     ApplicationCacheService cacheService,
     IDataKeyRepository dataKeyRepository,
     ITransactionManager transactionManager,
     IEncryptionFactory encryptionFactory)
 {
     _cacheService       = cacheService;
     _dataKeyRepository  = dataKeyRepository;
     _transactionManager = transactionManager;
     _encryptionFactory  = encryptionFactory;
 }
        public static void Register(string key, IEncryptionFactory factory)
        {
            key = key.ToLower();

            if (encryptors.ContainsKey(key))
            {
                throw new Exception("加密标志已注册 => " + key);
            }

            encryptors.Add(key, factory);
        }
Beispiel #5
0
 public CreateSharedDataKeysApplicationKernalService(
     ITransactionManager transactionManager,
     ILogger <CreateSharedDataKeysApplicationKernalService> logger,
     ICommandRepository <SharedDataKey> commandRepository,
     ICreateSharedDataKeyCommand createSharedDataKeyCommand,
     IChangeSharedDataKeyCommand changeSharedDataKeyCommand,
     IEncryptionFactory encryptionFactory)
 {
     _transactionManager         = transactionManager;
     _logger                     = logger;
     _commandRepository          = commandRepository;
     _createSharedDataKeyCommand = createSharedDataKeyCommand;
     _changeSharedDataKeyCommand = changeSharedDataKeyCommand;
     _encryptionFactory          = encryptionFactory;
 }
Beispiel #6
0
 public ValidateEncryptionKeys(IEncryptionFactory factory)
 {
     _factory = factory;
 }
Beispiel #7
0
 public FileBuilder(IEncryptionFactory encryptionFactory, IFileReaderFactory fileReaderFactory)
 {
     this._encryptionFactory = encryptionFactory;
     this._fileReaderFactory = fileReaderFactory;
 }
Beispiel #8
0
        public string Authenticated(AppUser login)
        {
            try
            {
                AppUserRepository appUserRepository = new AppUserRepository(context);
                AppUser           findAppUser       = appUserRepository.FindByName(login.Name);

                if (findAppUser != null)
                {
                    //if (login.Name != "TouresBalon")
                    //{

                    //        //if (findAppUser.Active)
                    //        //{
                    //            string path = "LDAP://DC=" + System.Configuration.ConfigurationManager.AppSettings["domainActiveDirectory"] + ",DC=" + System.Configuration.ConfigurationManager.AppSettings["domainActiveDirectoryExtension"];
                    //            string filterAttribute = "";

                    //            string domainAndUsername = System.Configuration.ConfigurationManager.AppSettings["domainActiveDirectory"] + "." + System.Configuration.ConfigurationManager.AppSettings["domainActiveDirectoryExtension"] + @"\" + login.Name;
                    //            DirectoryEntry entry = new DirectoryEntry(path, domainAndUsername, login.Password);

                    //            try
                    //            {
                    //                object obj = entry.NativeObject;
                    //                DirectorySearcher search = new DirectorySearcher(entry);
                    //                search.Filter = "(SAMAccountName=" + login.Name + ")";
                    //                search.PropertiesToLoad.Add("cn");
                    //                SearchResult result = search.FindOne();

                    //                if (null == result)
                    //                {
                    //                    return LoginStatus.WRONG_PASSWORD;
                    //                }
                    //                path = result.Path;
                    //                filterAttribute = (String)result.Properties["cn"][0];
                    //            }
                    //            catch (Exception ex)
                    //            {
                    //                return LoginStatus.WRONG_PASSWORD;
                    //            }
                    //            return LoginStatus.OK;
                    //        //}
                    //        //else
                    //        //{
                    //        //    return LoginStatus.USER_INACTIVE;
                    //        //}

                    //}
                    //else
                    //{

                    EncryptionFactory  factory   = new EncryptionFactory();
                    IEncryptionFactory encriptor = factory.GetProvider(EncryptionProvider.TripeDes);
                    encriptor.Key = ConfigurationManager.AppSettings["encriptorKey"];
                    encriptor.IV  = ConfigurationManager.AppSettings["encriptorIV"];
                    string encriptPassword = encriptor.Encrypt(login.Password);
                    if (encriptPassword == findAppUser.Password)
                    {
                        return(LoginStatus.OK);
                    }
                    else
                    {
                        return(LoginStatus.WRONG_PASSWORD);
                    }
                    //}
                }
                else
                {
                    return(LoginStatus.APPUSER_NOT_FOUND);
                }
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
                throw;
            }
        }