static void TestNameEncryption() { string fileName = "Обучение CRM.docx"; Console.WriteLine("Source name: " + fileName); IHashService md5 = new Md5HashService(); IDecodingService unicodeDecoder = new Utf8Coder(); ICryptoService aes = new AesCryptoService(); EncryptionService svc = new EncryptionService(md5, unicodeDecoder, aes); svc.SetCipherData("qazqaz", "qwer"); string ecryptedName = svc.Process(fileName, CipherDirection.Encryption, new Base64Coder(), new Utf8Coder()); Console.WriteLine("Encrypted name: " + ecryptedName); string decryptedName = svc.Process(ecryptedName, CipherDirection.Decryption, new Utf8Coder(), new Base64Coder()); Console.WriteLine("Decrypted name: " + decryptedName); }
public void Setup() { _utf8Coder = new Utf8Coder(); }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { services.AddCors(); //auto mapper var mapperConfig = new MapperConfiguration(cfg => { var photoCoder = new Utf8Coder(); cfg.AddProfile(new RequestToDomainProfile(photoCoder)); cfg.AddProfile(new DomainToResponseProfile(photoCoder)); cfg.AddProfile(new DomainToDbMappingProfiles()); cfg.AddProfile(new DbToDomainMappingProfiles()); }); IMapper mapper = mapperConfig.CreateMapper(); services.AddSingleton(mapper); //FactsToJsonMapper services.AddSingleton <IFactsToJsonMapper, FactsToNewtonJsonMapper>(); //repos RegisterEfCoreRepository(services); RegisterTransactionalDapperRepository(services); //app services services.AddScoped <IEventService, EventService>(); services.AddScoped <ITrackerService, TrackerService>(); services.AddScoped <IBackgroundStatisticGenerator, StatisticGenerator>(); services.AddScoped <IUserService, UserService>(); services.AddScoped <IStatisticsService, StatisticsService>(); //add calculators to statistic services AddMultipleTrackersStatisticsProvider(services); AddSingleTrackerStatisticsProvider(services); //password hasher services.AddSingleton <IPasswordHasher, PasswordHasher>(); //jwt var jwtOptions = new JwtOptions(); Configuration.GetSection(nameof(JwtOptions)).Bind(jwtOptions); services.AddSingleton(jwtOptions); services.AddSingleton <IJwtIssuer, JwtIssuer>(); services .AddAuthentication(JwtBearerDefaults.AuthenticationScheme) .AddJwtBearer(options => { options.TokenValidationParameters = new TokenValidationParameters() { ValidateAudience = false, ValidateIssuer = false, ValidateIssuerSigningKey = true, IssuerSigningKey = new SymmetricSecurityKey(Encoding.ASCII.GetBytes(jwtOptions.Secret)), ValidateLifetime = true }; }); //swagger services.AddSwaggerGen(swaggerGenOptions => { swaggerGenOptions.SwaggerDoc("v1", new OpenApiInfo { Title = "ItHappened API", Version = "v1" }); // Bearer token authentication var securityDefinition = new OpenApiSecurityScheme { Name = "Bearer", BearerFormat = "JWT", Scheme = "bearer", Description = "Specify the authorization token.", In = ParameterLocation.Header, Type = SecuritySchemeType.Http, }; swaggerGenOptions.AddSecurityDefinition("jwt_auth", securityDefinition); // Make sure swagger UI requires a Bearer token specified var securityScheme = new OpenApiSecurityScheme { Reference = new OpenApiReference { Id = "jwt_auth", Type = ReferenceType.SecurityScheme } }; var securityRequirements = new OpenApiSecurityRequirement() { { securityScheme, new string[] { } }, }; swaggerGenOptions.AddSecurityRequirement(securityRequirements); }); //hangfire services.AddHangfire(configuration => configuration.UseMemoryStorage()); services.AddHangfireServer(); //ignore null properties while Serialization to json services.AddMvc().AddJsonOptions(options => options.JsonSerializerOptions.IgnoreNullValues = true); }