public EncryptedValue Encrypt(string value, OutgoingContext outgoingContext) { if (string.IsNullOrEmpty(encryptionKeyIdentifier)) { throw new InvalidOperationException("It is required to set the rijndael key identifer."); } AddKeyIdentifierHeader(outgoingContext); using (var rijndael = new RijndaelManaged()) { rijndael.Key = encryptionKey; rijndael.Mode = CipherMode.CBC; rijndael.GenerateIV(); using (var encryptor = rijndael.CreateEncryptor()) using (var memoryStream = new MemoryStream()) using (var cryptoStream = new CryptoStream(memoryStream, encryptor, CryptoStreamMode.Write)) using (var writer = new StreamWriter(cryptoStream)) { writer.Write(value); writer.Flush(); cryptoStream.Flush(); cryptoStream.FlushFinalBlock(); return(new EncryptedValue { EncryptedBase64Value = Convert.ToBase64String(memoryStream.ToArray()), Base64Iv = Convert.ToBase64String(rijndael.IV) }); } } }
internal OutgoingContext InvokeSendPipeline(DeliveryOptions deliveryOptions, LogicalMessage message) { var context = new OutgoingContext(CurrentContext, deliveryOptions, message); InvokePipeline(outgoingBehaviors, context); return(context); }
public object MutateOutgoing(object message, OutgoingContext outgoingContext) { this.outgoingContext = outgoingContext; ForEachMember( message, EncryptMember, IsEncryptedMember ); return(message); }
protected virtual void AddKeyIdentifierHeader(OutgoingContext outgoingContext) { var outgoingHeaders = outgoingContext.OutgoingLogicalMessage.Headers; outgoingHeaders[Headers.RijndaelKeyIdentifier] = encryptionKeyIdentifier; if (!outgoingHeaders.ContainsKey(Headers.RijndaelKeyIdentifier)) { outgoingHeaders.Add(Headers.RijndaelKeyIdentifier, encryptionKeyIdentifier); } }
public void Should_not_blow_up() { var metadata = new MessageMetadata(timeToBeReceived: TimeSpan.FromDays(1)); var message = new LogicalMessage(metadata, new MessageWithNullDataBusProperty(), new Dictionary <string, string>(), null); var context = new OutgoingContext(null, new SendOptions(Address.Parse("MyEndpoint")), message); using (var stream = new MemoryStream()) { new BinaryFormatter().Serialize(stream, "test"); stream.Position = 0; sendBehavior.Invoke(context, () => { }); } }
void Invoke(LogicalMessage message) { var context = new OutgoingContext(null, new SendOptions(Address.Parse("MyEndpoint")), message); sendBehavior.Invoke(context, () => { }); }
public ManifestOutgoingController(OutgoingContext _context) { context = _context; }
protected override void AddKeyIdentifierHeader(OutgoingContext outgoingContext) { OutgoingKeyIdentifierSet = true; }