private void btnCompress_Click(object sender, EventArgs e) { time.Stop(); NewSerializer newSerializer = new NewSerializer(); SaveFileDialog dlg = new SaveFileDialog(); dlg.FileName = "World"; CompressionAlgs algorithms = new CompressionAlgs(pluginPath); if (algorithms.objects.Count == 0) { MessageBox.Show("No plugins"); return; } AddCompressorDecorator(algorithms); string filter = string.Empty; foreach (ICompression alg in algorithms.objects) { filter += alg.Name + " archive (*" + alg.Format + ")|*" + alg.Format + "|"; } dlg.Filter = filter.TrimEnd('|'); bool result = dlg.ShowDialog() == DialogResult.OK; if (result == true) { BinarySerialization bin = new BinarySerialization(); XmlSerialization xml = new XmlSerialization(); TextSerialization text = new TextSerialization(); string ext = Path.GetExtension(dlg.FileName); string name = dlg.FileName.Replace(ext, ""); ICompression compressor = algorithms.objects.Find(obj => obj.Format == ext); xml.Serialize(star, name + ".xml"); compressor.Compress(name + ".xml", name + ".xml" + ext); File.Delete(name + ".xml"); bin.Serialize(star, name + ".bin"); compressor.Compress(name + ".bin", name + ".bin" + ext); File.Delete(name + ".bin"); text.Serialize(star, name + ".txt"); compressor.Compress(name + ".txt", name + ".txt" + ext); File.Delete(name + ".txt"); } time.Start(); }
public Bitmap EncodeMessageInImage(Bitmap coverImage, string message, string encryptionKey, string stegoSeed, bool encrypt = true, bool compress = true) { try { if (encrypt) { message = _cryptoMethod.Encrypt(message, encryptionKey); } byte[] byteMessage = Encoding.UTF8.GetBytes(message); if (compress) { byteMessage = _compressMethod.Compress(byteMessage); } Bitmap stegoObject = _stegoMethod.Encode(coverImage, stegoSeed, byteMessage); return(stegoObject); } catch (NotifyUserException) { throw; } catch (AbortActionException) { throw; } }
public string Compress(string stringToCompress) { byte[] input = Encoding.UTF8.GetBytes(stringToCompress); var compressesInput = _compression.Compress(input); return(Convert.ToBase64String(compressesInput)); }
public static string EncryptBlock(string textToEncrypt, byte [] password) { if (string.IsNullOrEmpty(textToEncrypt)) { throw new ArgumentNullException("textToEncrypt"); } if (password == null) { throw new ArgumentNullException("password"); } var aes = new Aes(); using (var rngCsp = new RNGCryptoServiceProvider()) { var salt = new byte[32]; rngCsp.GetBytes(salt); var compressed = Compressor.Compress(ByteHelpers.GetBytes(textToEncrypt)); var encrpytedMessage = aes.Encrypt(compressed, Convert.ToBase64String(password), salt, 70000); byte[] fullMessage = ByteHelpers.Combine(salt, encrpytedMessage); return(Convert.ToBase64String(fullMessage)); } }
public async Task <IMessage> GetMessage(IPayload payload) { var data = serializer.Serialize(payload.Data); data = compression.Compress(data); data = encryption.Encrypt(data); var eventId = eventHolder.GetEvent(payload.Event); return(await Task.FromResult((IMessage) new Message { EventId = eventId, Data = data }).ConfigureAwait(false)); }
public byte[] Compress(byte[] data) { Ensure.ArgumentNotNull(data, "data"); using (var stream = data.ToStream()) { var compressedData = _compression.Compress(stream); return(compressedData); } }
public byte[] Serialize <TObject>(TObject objectToSerialize) { if (typeof(TObject) != typeof(IDiagramModel)) { return(new byte[0]); } var serializer = _modelingXmlSerializerRepository.SerializerFor <IDiagramModel>(); using (var serializationContext = SerializationTransaction.Create()) return(_compress.Compress(XmlHelper.XmlContentToByte(serializer.Serialize(objectToSerialize, serializationContext)))); }
public string Serialise(string key, string iv) { var serlizedBasicClient = new SerlializedBasicClient() { TokenTable = _tokenTableSet, GeneratorSettings = (GeneratorSettings)_tableGenerator.GetSettings(), ServiceSettings = (ServiceSettings)_basicService.GetSettings() }; _encryption.SetKeyAndIv(key, iv); return(_encryption.EncryptString(_compression.Compress(_serialisation.Serliaise(serlizedBasicClient)))); }
public void SetChunksToFile(IEnumerable <DbChunk> chunks, string filename) { List <DbChunk> compressed = new List <DbChunk>(); foreach (DbChunk c in chunks) { byte[] b; if (c.Chunk == null) { b = null; } else { b = d_Compression.Compress(c.Chunk); } compressed.Add(new DbChunk() { Position = c.Position, Chunk = b }); } d_ChunkDb.SetChunksToFile(compressed, filename); }
internal static async Task <string> DeflateEncode(string val, ICompression compression) { var strArr = Encoding.UTF8.GetBytes(val); using (var memoryStream = new MemoryStream(strArr)) { using (var compressed = new MemoryStream()) { await compression.Compress(memoryStream, compressed); compressed.Position = 0; return(Convert.ToBase64String(compressed.GetBuffer(), 0, (int)compressed.Length, Base64FormattingOptions.None)); } } }
public Message GetMessage <TData>(IPayload <TData> payload) { using (var stream = new ValueStream(arrayPool)) { var commandId = commandHolder.GetCommand(payload.CommandType); stream.WriteInt32(commandId); serializer.Serialize(stream, payload.Data); compression.Compress(stream); encryption.Encrypt(stream); return(new Message(stream.Buffer, (int)stream.Length)); } }
private void Encrypt(List <int> seeds, BasicResult result) { if (_settings.Encrypt) { var seed = string.Join("|", seeds); var fullString = seed + "[ENDSEED]" + result.Value; var doubleArray = fullString.Select(c => (int)c).ToArray(); var flatArray = string.Join("|", doubleArray); var compressedFlatArray = _compression.Compress(flatArray); result.Value = _encryption.EncryptString(compressedFlatArray); } else { result.Seed = seeds; } }
internal static async Task <byte[]> DeflateCompress(byte[] val, ICompression compression) { //var strArr = Encoding.UTF8.GetBytes(val); using (var memoryStream = new MemoryStream(val)) { using (var compressed = new MemoryStream()) { await compression.Compress(memoryStream, compressed); compressed.Position = 0; var result = new byte[compressed.Length]; Array.Copy(compressed.GetBuffer(), result, result.Length); return(result); } } }
protected override void ProcessCompression(ICompression compression, Stream input, Stream output) { compression.Compress(input, output); }
public void Run() { using var input = _readable.OpenReader(); Result = Compressor.Compress(input, Temp); }
public byte[] Serialize <TObject>(TObject objectToSerialize) { return(_compression.Compress(_serializationManager.Serialize(objectToSerialize))); }
public virtual void Compress(string inputFile, string outputFile) { compressor.Compress(inputFile, outputFile); }