I'm working with the sample data posted at
http://code.google.com/apis/safebrowsing/developers_guide.html and
seem to be having a lot of trouble coming up with the correct MAC.
I thought I found exactly what I'm looking for at
http://stackoverflow.com/questions/181994/code-to-verify-updates-from-the-google-safe-browsing-api,
but the examples there use a language I'm not familiar with.
I'm using C# and the main thing I seem to be missing is the decoding
of the clientkey. I tried including it unchanges, decoded to two hex
characters per byte, and converting the bytes directly to characters
but I cannot get the expected MAC.
Any suggestions? Here's my code:
string clientKey = "8eirwN1kTwCzgWA2HxTaRQ==";
byte[] results = Convert.FromBase64String(clientKey);
StringBuilder sb = new StringBuilder();
foreach (byte b in results)
sb.Append(b.ToString("x2"));
string table = "+8070465bdf3b9c6ad6a89c32e8162ef1\t\n
+86fa593a025714f89d6bc8c9c5a191ac\t\n+bbbd7247731cbb7ec1b3a5814ed4bc9d
\t\n";
string mac = "dRalfTU+bXwUhlk0NCGJtQ==";
string s = String.Format("{0}:coolgoog:{1}:coolgoog:{0}", sb.ToString
(), table);
MD5 md5 = MD5.Create();
results = md5.ComputeHash(Encoding.Default.GetBytes(s));
s = Convert.ToBase64String(results);
if (s != mac)
s = "Whoops! Doesn't match!";