This is a unit test to ensure 8 bit data (00-FF) can be placed in an string moved to a byte array and vice versa and nothing is lost in this conversion.
it seems that base64String does not seem to be able to hold the correct 8 bit data and as a result content of dest and fileblock1 wont match.
What improper encoding am i doing wrong?
Code:string filename; FileInfo ff; FileStream fss; BinaryReader br; filename = textBox1.Text; ff = new FileInfo(filename); byte[] FileBlock1 = new byte[ff.Length]; fss = new FileStream(filename, FileMode.Open); br = new BinaryReader(fss); br.Read(FileBlock1, 0, (int)ff.Length); fss.Close(); // file block shows the correct data in the file string base64String = null; int position = -1; System.Text.UTF8Encoding encoding = new System.Text.UTF8Encoding(); base64String = System.Convert.ToBase64String(FileBlock1, 0, FileBlock1.Length); byte[] dest = new byte[FileBlock1.Length]; Array.Copy(encoding.GetBytes(base64String), dest, FileBlock1.Length); if (ByteArrayCompare(dest, FileBlock1, ref position)) { textBox2.Text += "matched\r\n"; } else { textBox2.Text += "DID not matched .position" + position.ToString() + "\r\n"; ; }




Reply With Quote