Exemplo n.º 1
0
        public void Aes256_GCM_Stream()
        {
            var hashKey = _hashingProvider.GetHashKey(Passphrase, Salt, 32);

            _output.WriteLine(Encoding.UTF8.GetString(hashKey));
            _output.WriteLine($"HashKey: {Encoding.UTF8.GetString(hashKey)}");

            var encryptionProvider = new AesGcmEncryptionProvider(hashKey);
            var encryptedStream    = encryptionProvider.Encrypt(new MemoryStream(_data));
            var decryptedStream    = encryptionProvider.Decrypt(encryptedStream);

            Assert.Equal(_data, decryptedStream.ToArray());
        }
Exemplo n.º 2
0
        public async Task Aes256_GCM_StreamAsync()
        {
            var hashKey = await _hashingProvider
                          .GetHashKeyAsync(Passphrase, Salt, 32)
                          .ConfigureAwait(false);

            _output.WriteLine(Encoding.UTF8.GetString(hashKey));
            _output.WriteLine($"HashKey: {Encoding.UTF8.GetString(hashKey)}");

            var encryptionProvider = new AesGcmEncryptionProvider(hashKey);
            var encryptedStream    = await encryptionProvider.EncryptAsync(new MemoryStream(_data));

            var decryptedStream = encryptionProvider.Decrypt(encryptedStream);

            Assert.Equal(_data, decryptedStream.ToArray());
        }
Exemplo n.º 3
0
        public void Aes192_GCM()
        {
            var hashKey = _hashingProvider.GetHashKey(Passphrase, Salt, 24);

            _output.WriteLine(Encoding.UTF8.GetString(hashKey));
            _output.WriteLine($"HashKey: {Encoding.UTF8.GetString(hashKey)}");

            var encryptionProvider = new AesGcmEncryptionProvider(hashKey);

            var encryptedData = encryptionProvider.Encrypt(_data);

            _output.WriteLine($"Encrypted: {Encoding.UTF8.GetString(encryptedData)}");

            var decryptedData = encryptionProvider.Decrypt(encryptedData);

            _output.WriteLine($"Data: {Encoding.UTF8.GetString(_data)}");
            _output.WriteLine($"Decrypted: {Encoding.UTF8.GetString(decryptedData)}");

            Assert.Equal(_data, decryptedData);
        }
Exemplo n.º 4
0
        public async Task Aes128_GCM_BouncyCastle()
        {
            var hashKey = await _hashingProvider
                          .GetHashKeyAsync(Passphrase, Salt, 16)
                          .ConfigureAwait(false);

            _output.WriteLine(Encoding.UTF8.GetString(hashKey));
            _output.WriteLine($"HashKey: {Encoding.UTF8.GetString(hashKey)}");

            var encryptionProvider = new AesGcmEncryptionProvider(hashKey, _hashingProvider.Type);

            var encryptedData = encryptionProvider.Encrypt(_data);

            _output.WriteLine($"Encrypted: {Encoding.UTF8.GetString(encryptedData)}");

            var decryptedData = encryptionProvider.Decrypt(encryptedData);

            _output.WriteLine($"Data: {Encoding.UTF8.GetString(_data)}");
            _output.WriteLine($"Decrypted: {Encoding.UTF8.GetString(decryptedData)}");

            Assert.Equal(_data, decryptedData);
        }
Exemplo n.º 5
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddControllers();

            var loggerFactory = LoggerFactory.Create(builder => builder.AddConsole().SetMinimumLevel(LogLevel.Information));

            var metricsProvider = new PrometheusMetricsProvider()
                                  .AddDotNetRuntimeStats();

            var serializationProvider = new Utf8JsonProvider();
            var hashingProvider       = new Argon2IDHasher();
            var hashKey = hashingProvider
                          .GetHashKeyAsync("passwordforencryption", "saltforencryption", 32)
                          .GetAwaiter()
                          .GetResult();

            var encryptionProvider  = new AesGcmEncryptionProvider(hashKey, hashingProvider.Type);
            var compressionProvider = new LZ4PickleProvider();

            var rabbitService = new RabbitService(
                "Config.json",
                serializationProvider,
                encryptionProvider,
                compressionProvider,
                loggerFactory);

            services.AddSingleton(
                s =>
            {
                return(new ConsumerDataflowService(
                           s.GetRequiredService <IConfiguration>(),
                           loggerFactory,
                           rabbitService,
                           serializationProvider,
                           compressionProvider,
                           encryptionProvider,
                           metricsProvider));
            });
        }