/// <summary> /// Serialize messages using the BSON message serializer with AES Encryption /// </summary> /// <param name="configurator"></param> /// <param name="symmetricKey"> /// Cryptographic key for both encryption of plaintext message and decryption of ciphertext message /// </param> public static void UseEncryption(this IEventHubFactoryConfigurator configurator, byte[] symmetricKey) { var keyProvider = new ConstantSecureKeyProvider(symmetricKey); var streamProvider = new AesCryptoStreamProviderV2(keyProvider); configurator.UseEncryptedSerializerV2(streamProvider); }
public void SetupSerializationTest() { if (_serializerType == typeof(JsonMessageSerializer)) { Serializer = new JsonMessageSerializer(); Deserializer = new JsonMessageDeserializer(JsonMessageSerializer.Deserializer); } else if (_serializerType == typeof(BsonMessageSerializer)) { Serializer = new BsonMessageSerializer(); Deserializer = new BsonMessageDeserializer(BsonMessageSerializer.Deserializer); } else if (_serializerType == typeof(XmlMessageSerializer)) { Serializer = new XmlMessageSerializer(); Deserializer = new XmlMessageDeserializer(JsonMessageSerializer.Deserializer); } else if (_serializerType == typeof(EncryptedMessageSerializer)) { ISymmetricKeyProvider keyProvider = new TestSymmetricKeyProvider(); var streamProvider = new AesCryptoStreamProvider(keyProvider, "default"); Serializer = new EncryptedMessageSerializer(streamProvider); Deserializer = new EncryptedMessageDeserializer(BsonMessageSerializer.Deserializer, streamProvider); } else if (_serializerType == typeof(EncryptedMessageSerializerV2)) { var key = new byte[] { 31, 182, 254, 29, 98, 114, 85, 168, 176, 48, 113, 206, 198, 176, 181, 125, 106, 134, 98, 217, 113, 158, 88, 75, 118, 223, 117, 160, 224, 1, 47, 162 }; var keyProvider = new ConstantSecureKeyProvider(key); var streamProvider = new AesCryptoStreamProviderV2(keyProvider); Serializer = new EncryptedMessageSerializerV2(streamProvider); Deserializer = new EncryptedMessageDeserializerV2(BsonMessageSerializer.Deserializer, streamProvider); } #if !NETCORE else if (_serializerType == typeof(BinaryMessageSerializer)) { Serializer = new BinaryMessageSerializer(); Deserializer = new BinaryMessageDeserializer(); } #endif else { throw new ArgumentException("The serializer type is unknown"); } }
public static void UseAwsKeyManagementServiceSerializer(this IBusFactoryConfigurator configurator, IKeyManagementService keyManagementService, IEncryptionContextBuilder encryptionContextBuilder, string kmsKeyId) { var kmsSecureKeyProvider = new KmsSecureKeyProvider(keyManagementService, encryptionContextBuilder, kmsKeyId); var aesCryptoStreamProvider = new AesCryptoStreamProviderV2(kmsSecureKeyProvider); configurator.SetMessageSerializer(() => new EncryptedMessageSerializerV2(aesCryptoStreamProvider)); configurator.AddMessageDeserializer(EncryptedMessageSerializer.EncryptedContentType, () => new EncryptedMessageDeserializerV2(BsonMessageSerializer.Deserializer, aesCryptoStreamProvider)); }
protected override void ConfigureServiceBusBus(IServiceBusBusFactoryConfigurator configurator) { var key = new byte[] { 31, 182, 254, 29, 98, 114, 85, 168, 176, 48, 113, 206, 198, 176, 181, 125, 106, 134, 98, 217, 113, 158, 88, 75, 118, 223, 117, 160, 224, 1, 47, 162 }; var keyProvider = new ConstantSecureKeyProvider(key); var streamProvider = new AesCryptoStreamProviderV2(keyProvider); configurator.UseEncryptedSerializerV2(streamProvider); base.ConfigureServiceBusBus(configurator); }
/// <summary> /// Serialize messages using the BSON message serializer with AES Encryption /// </summary> /// <param name="configurator"></param> /// <param name="keyProvider"> /// The custom key provider to provide the symmetric key for encryption of plaintext message and decryption of ciphertext message /// </param> public static void UseEncryption(this IEventHubFactoryConfigurator configurator, ISecureKeyProvider keyProvider) { var streamProvider = new AesCryptoStreamProviderV2(keyProvider); configurator.UseEncryptedSerializerV2(streamProvider); }
/// <summary> /// Serialize messages using the BSON message serializer with AES Encryption /// </summary> /// <param name="configurator"></param> /// <param name="keyProvider">The custom key provider to provide the symmetric key for encryption of plaintext message and decryption of ciphertext message</param> public static void UseEncryption(this IReceiveEndpointConfigurator configurator, ISecureKeyProvider keyProvider) { var streamProvider = new AesCryptoStreamProviderV2(keyProvider); configurator.UseEncryptedSerializerV2(streamProvider); }