public async Task Works()
    {
        var target = new ClassWithString
        {
            Property = "Foo"
        };

        using var factory   = new EncryptionFactory();
        using var algorithm = CryptoBuilder.Build();
        var serializer = new JsonSerializer
        {
            ContractResolver = factory.GetContractResolver()
        };

        string serialized;

        using (factory.GetEncryptSession(algorithm))
        {
            await Task.Delay(1);

            serialized = serializer.Serialize(target);
        }

        using (factory.GetDecryptSession(algorithm))
        {
            await Task.Delay(1);

            var result = serializer.Deserialize <ClassWithString>(serialized);
            Assert.Equal("Foo", result.Property);
        }
    }
    public void RoundTrip()
    {
        var factory    = new EncryptionFactory();
        var serializer = new JsonSerializer
        {
            ContractResolver = factory.GetContractResolver()
        };

        using (var algorithm = CryptoBuilder.Build())
        {
            string serialized;
            using (factory.GetEncryptSession(algorithm))
            {
                var instance = new ClassToSerialize
                {
                    Property1 = "Property1Value",
                    Property2 = "Property2Value"
                };
                serialized = serializer.Serialize(instance);
            }
            using (factory.GetDecryptSession(algorithm))
            {
                var result = serializer.Deserialize <ClassToSerialize>(serialized);
                ObjectApprover.VerifyWithJson(result);
            }
        }
    }
예제 #3
0
        /// <summary>
        /// Configures Rebus to encrypt messages.
        /// </summary>
        public static void EnableJsonEncryption(this RebusConfigurer configurer, EncryptionFactory encryptionFactory, EncryptStateBuilder encryptStateBuilder, DecryptStateBuilder decryptStateBuilder)
        {
            Guard.AgainstNull(nameof(configurer), configurer);
            Guard.AgainstNull(nameof(encryptionFactory), encryptionFactory);
            Guard.AgainstNull(nameof(encryptStateBuilder), encryptStateBuilder);
            Guard.AgainstNull(nameof(decryptStateBuilder), decryptStateBuilder);

            configurer.Options(options =>
            {
                options.Decorate <IPipeline>(
                    resolutionContext =>
                {
                    var pipeline = resolutionContext.Get <IPipeline>();
                    var injector = new PipelineStepInjector(pipeline);

                    var decryptStep = new DecryptStep(encryptionFactory, decryptStateBuilder);
                    injector.OnReceive(decryptStep, PipelineRelativePosition.Before, typeof(DeserializeIncomingMessageStep));

                    var encryptStep = new EncryptStep(encryptionFactory, encryptStateBuilder);
                    injector.OnSend(encryptStep, PipelineRelativePosition.Before, typeof(SerializeOutgoingMessageStep));

                    return(injector);
                });
            });
        }
예제 #4
0
 public StorageFactory(
     StorageFactoryListener storageFactoryListener,
     StorageFactoryConfig storageFactoryConfig,
     SettingsManager settingsManager,
     StorageSettingsHelper storageSettingsHelper,
     TenantManager tenantManager,
     CoreBaseSettings coreBaseSettings,
     PathUtils pathUtils,
     EmailValidationKeyProvider emailValidationKeyProvider,
     IOptionsMonitor <ILog> options,
     IHttpContextAccessor httpContextAccessor,
     EncryptionSettingsHelper encryptionSettingsHelper,
     EncryptionFactory encryptionFactory)
 {
     StorageFactoryListener = storageFactoryListener;
     StorageFactoryConfig   = storageFactoryConfig;
     SettingsManager        = settingsManager;
     StorageSettingsHelper  = storageSettingsHelper;
     TenantManager          = tenantManager;
     CoreBaseSettings       = coreBaseSettings;
     PathUtils = pathUtils;
     EmailValidationKeyProvider = emailValidationKeyProvider;
     Options                  = options;
     HttpContextAccessor      = httpContextAccessor;
     EncryptionSettingsHelper = encryptionSettingsHelper;
     EncryptionFactory        = encryptionFactory;
 }
예제 #5
0
        public IActionResult ValidateParticipants([FromBody] Dictionary <string, string> santas)
        {
            if (Request.Headers.Authorization != AdminSecret)
            {
                return(Unauthorized());
            }

            var response = new ValidationDto();

            using (var db = new SantaContext())
            {
                foreach (var santa in santas)
                {
                    response.Santas.Add(santa.Key);
                    var thisSanta = db.Santas?.Find(Guid.Parse(santa.Value));
                    if (thisSanta == null)
                    {
                        return(UnprocessableEntity("EI KLAPI"));
                    }
                    var symmetricEncryptDecrypt = new EncryptionFactory();
                    var decryptedName           = symmetricEncryptDecrypt.Decrypt(thisSanta.DesignatedPerson, thisSanta.IVBase64, EncryptionKey);
                    response.Receivers.Add(decryptedName);
                }
            }
            response.Santas    = response.Santas.OrderBy(x => x).ToList();
            response.Receivers = response.Receivers.OrderBy(x => x).ToList();
            return(Ok(response));
        }
예제 #6
0
    void Usage(byte[] key)
    {
        #region RebugsUsage
        var activator = new BuiltinHandlerActivator();

        activator.Register(() => new Handler());
        var configurer = Configure.With(activator);

        var encryptionFactory = new EncryptionFactory();
        var settings          = new JsonSerializerSettings
        {
            TypeNameHandling = TypeNameHandling.All,
            ContractResolver = encryptionFactory.GetContractResolver()
        };
        configurer.Serialization(s => { s.UseNewtonsoftJson(settings); });
        configurer.EnableJsonEncryption(
            encryptionFactory: encryptionFactory,
            encryptStateBuilder: () =>
            (
                algorithm: new RijndaelManaged
        {
            Key = key
        },
                keyId: "1"
            ),
            decryptStateBuilder: (keyId, initVector) =>
            new RijndaelManaged
        {
            Key = key,
            IV  = initVector
        });
        #endregion
    }
    void Usage(byte[] key)
    {
        #region NsbUsage
        var configuration     = new EndpointConfiguration("NServiceBusSample");
        var serialization     = configuration.UseSerialization <NewtonsoftSerializer>();
        var encryptionFactory = new EncryptionFactory();
        serialization.Settings(
            new()
        {
            ContractResolver = encryptionFactory.GetContractResolver()
        });

        configuration.EnableJsonEncryption(
            encryptionFactory: encryptionFactory,
            encryptStateBuilder: () =>
            (
                algorithm: new RijndaelManaged
        {
            Key = key
        },
                keyId: "1"
            ),
            decryptStateBuilder: (keyId, initVector) =>
            new RijndaelManaged
        {
            Key = key,
            IV  = initVector
        });
        #endregion
    }
예제 #8
0
        public void ExecuteRetrieveFile(object args)
        {
            try
            {
                var deHideOption = this.GetDeHideOptionFromView((Window)args);

                if (deHideOption == null)
                {
                    return;
                }

                var ciphertext = HideLSB.DeHide(this._hiddenImageBitmapCache);

                IEncryption encryptor = EncryptionFactory.CreateEncryption(deHideOption.EncryptionAlg);
                var         plaintext = encryptor.Decrypt(ciphertext, this.StrPassword2UintArr(deHideOption.Password));
                var         deZipdata = Zip.Decompress(plaintext);

                if (File.Exists(deHideOption.FilePath))
                {
                    File.Delete(deHideOption.FilePath);
                }

                FileTransform.ByteArray2File(deHideOption.FilePath, deZipdata);

                this.ShowMessageBoxResource("RetrieveDone", "Hint", MessageBoxButton.OK, MessageBoxImage.Information);
            }
            catch (PasswordWrongException)
            {
                this.ShowMessageBoxResource("PasswordWrong", "Error");
            }
            catch (Exception)
            {
                this.ShowMessageBoxResource("PasswordWrong", "Error");
            }
        }
    public static void ConfigurationEncryption(this EndpointConfiguration endpointConfiguration)
    {
        var key               = Encoding.UTF8.GetBytes("gdDbqRpqdRbTs3mhdZh9qCaDaxJXl+e6");
        var serialization     = endpointConfiguration.UseSerialization <NewtonsoftSerializer>();
        var encryptionFactory = new EncryptionFactory();

        serialization.Settings(
            new JsonSerializerSettings
        {
            ContractResolver = encryptionFactory.GetContractResolver()
        });

        endpointConfiguration.EnableJsonEncryption(
            encryptionFactory: encryptionFactory,
            encryptStateBuilder: () =>
            (
                algorithm: new RijndaelManaged
        {
            Key = key
        },
                keyId: "1"
            ),
            decryptStateBuilder: (keyId, initVector) =>
            new RijndaelManaged
        {
            Key = key,
            IV  = initVector
        });
    }
        private AESEncryptor GetEncriptor(InAccessCode input)
        {
            var enc = (AESEncryptor)EncryptionFactory.GetEncryptor("AES");

            enc.Password = Convert.ToBase64String(Encoding.ASCII.GetBytes(AppSettings.GetAppSetting("Security.Encryptor.Password", "ebankIT | Omnichannel Innovation")));
            enc.Salt     = input.ExtendedProperty;
            return(enc);
        }
    static void Main()
    {
        // per system (periodically rotated)
        var key = Encoding.UTF8.GetBytes("gdDbqRpqdRbTs3mhdZh9qCaDaxJXl+e6");

        // per app domain
        using (var factory = new EncryptionFactory())
        {
            var serializer = new JsonSerializer
            {
                ContractResolver = factory.GetContractResolver()
            };

            // transferred as meta data with the serialized payload
            byte[] initVector;

            string serialized;

            // per serialize session
            using (var algorithm = new RijndaelManaged
            {
                Key = key
            })
            {
                initVector = algorithm.IV;
                using (factory.GetEncryptSession(algorithm))
                {
                    var instance = new ClassToSerialize
                    {
                        Property = "PropertyValue",
                    };
                    var builder = new StringBuilder();
                    using (var writer = new StringWriter(builder))
                    {
                        serializer.Serialize(writer, instance);
                    }
                    serialized = builder.ToString();
                }
            }

            // per deserialize session
            using (var algorithm = new RijndaelManaged
            {
                IV = initVector,
                Key = key
            })
            {
                using (factory.GetDecryptSession(algorithm))
                {
                    using var stringReader = new StringReader(serialized);
                    using var jsonReader   = new JsonTextReader(stringReader);
                    var deserialized = serializer.Deserialize <ClassToSerialize>(jsonReader);
                    Console.WriteLine(deserialized !.Property);
                }
            }
        }
        Console.ReadKey();
    }
 public DecryptRegistration(EncryptionFactory encryptionFactory, DecryptStateBuilder stateBuilder) :
     base(
         stepId: "NServiceBusJsonEncryptionDecrypt",
         behavior: typeof(DecryptBehavior),
         description: "Invokes the decryption logic",
         factoryMethod: _ => new DecryptBehavior(encryptionFactory, stateBuilder))
 {
     InsertBefore("MutateIncomingTransportMessage");
 }
예제 #13
0
 public EncryptRegistration(EncryptionFactory encryptionFactory, EncryptStateBuilder stateBuilder) :
     base(
         stepId: "NServiceBusJsonEncryptionEncrypt",
         behavior: typeof(EncryptBehavior),
         description: "Invokes the encrypt logic",
         factoryMethod: _ => new EncryptBehavior(encryptionFactory, stateBuilder))
 {
     InsertAfter("MutateOutgoingMessages");
 }
    static async Task Main()
    {
        var key = Encoding.UTF8.GetBytes("gdDbqRpqdRbTs3mhdZh9qCaDaxJXl+e6");

        Console.Title = "RebusSample";
        var directory = Directory.GetParent(Assembly.GetEntryAssembly().Location).FullName;

        var activator = new BuiltinHandlerActivator();

        activator.Register(() => new Handler());
        var configurer = Configure.With(activator);

        var encryptionFactory = new EncryptionFactory();
        var settings          = new JsonSerializerSettings
        {
            TypeNameHandling = TypeNameHandling.All,
            ContractResolver = encryptionFactory.GetContractResolver()
        };

        configurer.Serialization(s => { s.UseNewtonsoftJson(settings); });
        configurer.EnableJsonEncryption(
            encryptionFactory: encryptionFactory,
            encryptStateBuilder: () =>
            (
                algorithm: new RijndaelManaged
        {
            Key = key
        },
                keyId: "1"
            ),
            decryptStateBuilder: (keyId, initVector) =>
            new RijndaelManaged
        {
            Key = key,
            IV  = initVector
        });

        configurer.Transport(t =>
        {
            t.UseFileSystem(directory, "RebusSample");
        });

        var bus = configurer.Start();

        Console.WriteLine("Press any key to exit");

        await SendMessage(bus)
        .ConfigureAwait(false);

        Console.ReadKey();
        bus?.Dispose();
        encryptionFactory.Dispose();
        activator.Dispose();
    }
예제 #15
0
 public DiscDataStore(
     TenantManager tenantManager,
     PathUtils pathUtils,
     EmailValidationKeyProvider emailValidationKeyProvider,
     IOptionsMonitor <ILog> options,
     EncryptionSettingsHelper encryptionSettingsHelper,
     EncryptionFactory encryptionFactory)
     : base(tenantManager, pathUtils, emailValidationKeyProvider, options)
 {
     EncryptionSettingsHelper = encryptionSettingsHelper;
     EncryptionFactory        = encryptionFactory;
 }
예제 #16
0
 public NewtonsoftJSONService()
 {
     _encryptionFactory = new EncryptionFactory();
     Settings           = new JsonSerializerSettings()
     {
         Formatting                 = Formatting.None,
         TypeNameHandling           = TypeNameHandling.Auto,
         PreserveReferencesHandling = PreserveReferencesHandling.All,
         ReferenceLoopHandling      = ReferenceLoopHandling.Ignore,
         ObjectCreationHandling     = ObjectCreationHandling.Auto,
         ConstructorHandling        = ConstructorHandling.AllowNonPublicDefaultConstructor
     };
 }
    public void ExampleUsage()
    {
        // per system (periodically rotated)
        var key = Encoding.UTF8.GetBytes("gdDbqRpqdRbTs3mhdZh9qCaDaxJXl+e6");

        // per app domain
        using (var factory = new EncryptionFactory())
        {
            var serializer = new JsonSerializer
            {
                ContractResolver = factory.GetContractResolver()
            };

            // transferred as meta data with the serialized payload
            byte[] initVector;

            string serialized;

            // per serialize session
            using (var algorithm = new RijndaelManaged
            {
                Key = key
            })
            {
                initVector = algorithm.IV;
                using (factory.GetEncryptSession(algorithm))
                {
                    var instance = new ClassToSerialize
                    {
                        Property1 = "Property1Value",
                        Property2 = "Property2Value"
                    };
                    serialized = serializer.Serialize(instance);
                }
            }

            // per deserialize session
            using (var algorithm = new RijndaelManaged
            {
                IV = initVector,
                Key = key
            })
            {
                using (factory.GetDecryptSession(algorithm))
                {
                    var deserialized = serializer.Deserialize <ClassToSerialize>(serialized);
                    ObjectApprover.VerifyWithJson(deserialized);
                }
            }
        }
    }
예제 #18
0
 public DiscDataStore(
     TempStream tempStream,
     TenantManager tenantManager,
     PathUtils pathUtils,
     EmailValidationKeyProvider emailValidationKeyProvider,
     IHttpContextAccessor httpContextAccessor,
     IOptionsMonitor <ILog> options,
     EncryptionSettingsHelper encryptionSettingsHelper,
     EncryptionFactory encryptionFactory)
     : base(tempStream, tenantManager, pathUtils, emailValidationKeyProvider, httpContextAccessor, options)
 {
     EncryptionSettingsHelper = encryptionSettingsHelper;
     EncryptionFactory        = encryptionFactory;
 }
예제 #19
0
    static async Task Main()
    {
        var key = Encoding.UTF8.GetBytes("gdDbqRpqdRbTs3mhdZh9qCaDaxJXl+e6");

        Console.Title = "NServiceBusSample";

        var configuration     = new EndpointConfiguration("NServiceBusSample");
        var serialization     = configuration.UseSerialization <NewtonsoftSerializer>();
        var encryptionFactory = new EncryptionFactory();

        serialization.Settings(
            new JsonSerializerSettings
        {
            ContractResolver = encryptionFactory.GetContractResolver()
        });

        configuration.EnableJsonEncryption(
            encryptionFactory: encryptionFactory,
            encryptStateBuilder: () =>
            (
                algorithm: new RijndaelManaged
        {
            Key = key
        },
                keyId: "1"
            ),
            decryptStateBuilder: (keyId, initVector) =>
            new RijndaelManaged
        {
            Key = key,
            IV  = initVector
        });

        configuration.UsePersistence <LearningPersistence>();
        configuration.UseTransport <LearningTransport>();
        var endpointInstance = await Endpoint.Start(configuration)
        ;

        Console.WriteLine("Press any key to exit");

        await SendMessage(endpointInstance)
        ;

        Console.ReadKey();
        await endpointInstance.Stop()
        ;

        encryptionFactory.Dispose();
    }
예제 #20
0
 public StorageFactory(
     StorageFactoryListener storageFactoryListener,
     StorageFactoryConfig storageFactoryConfig,
     SettingsManager settingsManager,
     StorageSettingsHelper storageSettingsHelper,
     TenantManager tenantManager,
     CoreBaseSettings coreBaseSettings,
     PathUtils pathUtils,
     EmailValidationKeyProvider emailValidationKeyProvider,
     IOptionsMonitor <ILog> options,
     EncryptionSettingsHelper encryptionSettingsHelper,
     EncryptionFactory encryptionFactory) :
     this(storageFactoryListener, storageFactoryConfig, settingsManager, storageSettingsHelper, tenantManager, coreBaseSettings, pathUtils, emailValidationKeyProvider, options, null, encryptionSettingsHelper, encryptionFactory)
 {
 }
        public void CreateTripleDesTest()
        {
            var s3Des1 = EncryptionFactory.Create(EncryptionAlgorithm.TripleDES);
            var s3Des2 = EncryptionFactory.Create(EncryptionAlgorithm.TripleDES, new EncryptionOptions {
                TripleDesKeySize = TripleDesKeySize.b128
            });
            var s3Des3 = EncryptionFactory.Create(EncryptionAlgorithm.TripleDES, new EncryptionOptions {
                TripleDesKeySize = TripleDesKeySize.b192
            });

            Assert.IsInstanceOfType(s3Des1, typeof(SimpleTripleDes));
            Assert.IsInstanceOfType(s3Des2, typeof(SimpleTripleDes));
            Assert.IsInstanceOfType(s3Des3, typeof(SimpleTripleDes));
            Assert.AreEqual((s3Des1 as SimpleTripleDes).KeySizeMode, TripleDesKeySize.b128);
            Assert.AreEqual((s3Des2 as SimpleTripleDes).KeySizeMode, TripleDesKeySize.b128);
            Assert.AreEqual((s3Des3 as SimpleTripleDes).KeySizeMode, TripleDesKeySize.b192);
        }
    public void Simple()
    {
        var factory    = new EncryptionFactory();
        var serializer = new JsonSerializer
        {
            ContractResolver = factory.GetContractResolver()
        };

        using (var algorithm = CryptoBuilder.Build())
            using (factory.GetEncryptSession(algorithm))
            {
                var instance = new ClassToSerialize
                {
                    Property1 = "Property1Value",
                    Property2 = "Property2Value"
                };
                var result = serializer.Serialize(instance);
                Approvals.Verify(result);
            }
    }
예제 #23
0
        public void ExecuteHideFile(object args)
        {
            try
            {
                var hideOption = this.GetHideOptionFromView((Window)args);

                if (hideOption == null)
                {
                    return;
                }

                var fileBytesToHide      = FileTransform.File2ByteArray(hideOption.FilePath);
                var zipedCoverImageBytes = Zip.Compress(fileBytesToHide);

                IEncryption encryptor = EncryptionFactory.CreateEncryption(hideOption.EncryptionAlg);

                var ciphertext = encryptor.Encrypt(zipedCoverImageBytes, this.StrPassword2UintArr(hideOption.Password));

                var tmpBitmapCacheToHide =
                    this._coverImageBitmapCache.Clone(
                        new Rectangle(0, 0, this._coverImageBitmapCache.Width, this._coverImageBitmapCache.Height),
                        this._coverImageBitmapCache.PixelFormat);

                HideLSB.Hide(ref tmpBitmapCacheToHide, ciphertext);

                this._hiddenImageBitmapCache = tmpBitmapCacheToHide;
                this.HiddenImage             = FileTransform.Bitmap2BitmapImage(this._hiddenImageBitmapCache);
            }
            catch (ImageHideCapacityTooSmallException)
            {
                this.ShowMessageBoxResource("HidingCapacityNotEnough", "Hint", MessageBoxButton.OK, MessageBoxImage.Information);
            }
            catch (IOException)
            {
                this.ShowMessageBoxResource("FileOpenError", "Error");
            }
            catch (Exception)
            {
                this.ShowMessageBoxResource("UnknownError", "Error");
            }
        }
예제 #24
0
        /// <summary>
        /// 根据POST参数对象获取
        /// </summary>
        /// <param name="postData"></param>
        /// <param name="privateKey"></param>
        /// <param name="privateValue"></param>
        /// <returns></returns>
        public string GetSign(Dictionary <string, object> postData, string privateKey = "", string privateValue = "")
        {
            if (postData == null)
            {
                return(String.Empty);
            }

            var sortDic = new SortedDictionary <string, object>();

            foreach (var keyValuePair in postData)
            {
                sortDic.Add(keyValuePair.Key, keyValuePair.Value);
            }
            if (!privateKey.IsNullOrEmpty() && !privateValue.IsNullOrEmpty())
            {
                sortDic.Add(privateKey, privateValue);
            }
            var str       = string.Join("&", sortDic.Select(u => u.Key + "=" + u.Value));
            var signature = EncryptionFactory.Md5Encrypt(str);

            return(signature);
        }
예제 #25
0
    public static T Run <T>(T instance)
    {
        using (var factory = new EncryptionFactory())
            using (var algorithm = CryptoBuilder.Build())
            {
                var serializer = new JsonSerializer
                {
                    ContractResolver = factory.GetContractResolver()
                };

                string result;
                using (factory.GetEncryptSession(algorithm))
                {
                    result = serializer.Serialize(instance);
                }

                Approvals.Verify(result);
                using (factory.GetDecryptSession(algorithm))
                {
                    return(serializer.Deserialize <T>(result));
                }
            }
    }
예제 #26
0
    public static async Task <T> Run <T>(T instance, [CallerFilePath] string sourceFile = "")
    {
        using var factory   = new EncryptionFactory();
        using var algorithm = CryptoBuilder.Build();
        var serializer = new JsonSerializer
        {
            ContractResolver = factory.GetContractResolver()
        };

        string result;

        using (factory.GetEncryptSession(algorithm))
        {
            result = serializer.Serialize(instance);
        }

        await Verify(result, null, sourceFile);

        using (factory.GetDecryptSession(algorithm))
        {
            return(serializer.Deserialize <T>(result));
        }
    }
예제 #27
0
 public IActionResult Get(Guid code)
 {
     using (var db = new SantaContext())
     {
         Santa?santa = db.Santas?.First(x => x.Id == code);
         if (santa != null)
         {
             var symmetricEncryptDecrypt = new EncryptionFactory();
             var decryptedName           = symmetricEncryptDecrypt.Decrypt(santa.DesignatedPerson, santa.IVBase64, EncryptionKey);
             db.LogEntries?.Add(new LogEntry(santa.Id, Request.Headers["User-Agent"], Request.Headers["X-Forwarded-For"]));
             db.SaveChanges();
             var response = new SantaDto
             {
                 Name             = santa.Name,
                 DesignatedPerson = decryptedName
             };
             return(Ok(response));
         }
         else
         {
             return(BadRequest());
         }
     }
 }
예제 #28
0
        public DiscDataStore(string tenant, HandlerConfigurationElement handlerConfig, ModuleConfigurationElement moduleConfig)
        {
            _tenant = tenant;
            //Fill map path
            _modulename = moduleConfig.Name;
            _dataList   = new DataList(moduleConfig);
            foreach (DomainConfigurationElement domain in moduleConfig.Domains)
            {
                _mappedPaths.Add(domain.Name, new MappedPath(tenant, moduleConfig.AppendTenant, domain.Path, handlerConfig.GetProperties()));
            }
            //Add default
            _mappedPaths.Add(string.Empty, new MappedPath(tenant, moduleConfig.AppendTenant, PathUtils.Normalize(moduleConfig.Path), handlerConfig.GetProperties()));

            //Make expires
            _domainsExpires =
                moduleConfig.Domains.Cast <DomainConfigurationElement>().Where(x => x.Expires != TimeSpan.Zero).
                ToDictionary(x => x.Name,
                             y => y.Expires);
            _domainsExpires.Add(string.Empty, moduleConfig.Expires);

            var settings = moduleConfig.DisabledEncryption ? new EncryptionSettings() : EncryptionSettings.Load();

            crypt = EncryptionFactory.GetCrypt(moduleConfig.Name, settings);
        }
예제 #29
0
        public ChunkReader(
            DecodingConfiguration configuration,
            CompressionFactory compressionFactory,
            EncryptionFactory encryptionFactory)
        {
            if (configuration == null)
            {
                throw new ArgumentNullException("configuration");
            }

            if (compressionFactory == null)
            {
                throw new ArgumentNullException("compressionFactory");
            }

            if (encryptionFactory == null)
            {
                throw new ArgumentNullException("encryptionFactory");
            }

            _configuration      = configuration;
            _compressionFactory = compressionFactory;
            _encryptionFactory  = encryptionFactory;
        }
예제 #30
0
        /// <summary>
        /// Enable message property encryption.
        /// </summary>
        public static void EnableJsonEncryption(this EndpointConfiguration configuration, EncryptionFactory encryptionFactory, EncryptStateBuilder encryptStateBuilder, DecryptStateBuilder decryptStateBuilder)
        {
            Guard.AgainstNull(nameof(configuration), configuration);
            Guard.AgainstNull(nameof(encryptionFactory), encryptionFactory);
            Guard.AgainstNull(nameof(encryptStateBuilder), encryptStateBuilder);
            Guard.AgainstNull(nameof(decryptStateBuilder), decryptStateBuilder);

            var recoverability = configuration.Recoverability();

            recoverability.AddUnrecoverableException <KeyIdAndIvHeaderMismatchException>();
            var settings = configuration.GetSettings();

            settings.Set(encryptStateBuilder);
            settings.Set(decryptStateBuilder);
            settings.Set(encryptionFactory);
            configuration.EnableFeature <EncryptionFeature>();
        }