Hi. I can see you are converting your byte arrays to base64 strings so that you can perform comparisons. I think it would be more efficient to compare byte array against byte array so that you can skip out the conversion completely. There's no built in function to do this in C# (well, not one that I know anyway!) but you can easily make your own. Here's an example of how I would check if an array of bytes contains a desired sequence of bytes.
Code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication10
{
class Program
{
static void Main(string[] args)
{
byte[] buf = new byte[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
byte[] test1 = new byte[] { 2, 3, 4 };
byte[] test2 = new byte[] { 2, 4, 6 };
Console.WriteLine("buf contains test1 result: " + buf.SequenceContains(test1));
Console.WriteLine("buf contains test2 result: " + buf.SequenceContains(test2));
Console.Read();
}
}
public static class Exts
{
public static bool SequenceContains<T>(this T[] array, T[] sequence)
{
for (int i = 0; i < array.Length; i++)
{
if ((array.Length - i) < sequence.Length)
return false;
for (int x = 0; x < sequence.Length; x++)
{
if (!array[i + x].Equals(sequence[x]))
break;
if (x == (sequence.Length - 1))
return true;
}
}
return false;
}
}
}