My question is simply how I could join two byte arrays together and delimit them. In the following example I join them and write them as a single file. But, first I don't know how I could join them with a delimiter, a comma or something to separate them so that when my program starts it will be able to get them through a split. The code is the following:
//Everything seems fine -> Reading bytes
Console.WriteLine("[*] Reading Data...");
byte[] plainBytes = File.ReadAllBytes(file);
//Yep, got bytes -> Encoding
Console.WriteLine("[*] Encoding Data...");
byte[] encodedBytes = encodeBytes(plainBytes, pass);
Console.WriteLine("[*] Save to Output File... ");
//Leer el fichero
Console.WriteLine("[*] Reading fichero...");
byte[] Stub = File.ReadAllBytes("rutafichero");
// ::: Create new List of bytes
var list = new List<byte>();
list.AddRange(encodedBytes);
list.AddRange(Stub);
// ::: Call ToArray to convert List to array
byte[] resultado = list.ToArray();
//write bytes
File.WriteAllBytes(outFile, resultado);
//File.WriteAllBytes(outFile, encodedBytes);
Console.WriteLine("Done!");
Console.WriteLine("\n[*] File successfully encoded!");
Then my first byte array (file 1) will be + joined with the other byte array (file 2) and written to a single file. When I boot the resulting file I will be able to get the two arrays via a split. That is the objective that I wanted to carry out and that unfortunately I did not know how because firstly I do not know delimitar dos byte array combinados
and secondly how to extract them later. The goal was to do it with an assembly.
Personally, if you want to write 2 arrays to a file and be able to read them separately later, I would use the class
BinaryWriter
, to make it all automatic for you. The idea of using a split with a comma doesn't sound right to me in this case.For example, according to your example, starting from the following 2 byte arrays:
You can write the 2 arrays to a file as follows:
And then you can retrieve them using the class
BinaryReader
like this: