public override void Write(Utf8JsonWriter writer, T value, JsonSerializerOptions options) { var unprotectedBytes = _byteConverter.ToBytes(value); var protectedBytes = _dataProtector.Protect(unprotectedBytes); var cipherText = Convert.ToBase64String(protectedBytes); writer.WriteStringValue(cipherText); }
public string ToCipherText(T value, JsonSerializer serializer = null) { var unprotectedBytes = _byteConverter.ToBytes(value); var protectedBytes = _dataProtector.Protect(unprotectedBytes); var cipherText = Convert.ToBase64String(protectedBytes); return(cipherText); }
public override int Read(byte[] buffer, int offset, int count) { T[] bbuf = new T[count]; int read = _base.Read(bbuf, offset, count); buffer = _converter.ToBytes(bbuf); return(read); }
/// <summary> /// Execute an asynchronous continuation of Serialize->Send for an event. /// </summary> public Task PublishAsync(IEvent Event) { return(Task.Run( () => { try { return _converter.ToBytes(Event); } catch (Exception ex) { _logger.LogError(ex, $"Error converting {Event} to bytes."); throw; } }) .ContinueWith(t => _model.BasicPublish(_config.Exchange, _config.Routing, null, t.Result), TaskContinuationOptions.NotOnFaulted)); }