Has Anyone Got the MAC Working?

15 views
Skip to first unread message

Jon

unread,
Jun 16, 2009, 3:19:13 PM6/16/09
to Google Safe Browsing API
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!";

Dave Shanley

unread,
Jun 18, 2009, 5:01:24 AM6/18/09
to google-safe-...@googlegroups.com
I have never been able to get this to work, I have never seen anyone on here who has.

On Thu, Jun 18, 2009 at 10:00 AM, Dave Shanley <da...@quobix.com> wrote:
I have never been able to get this to work, I have never seen anyone on here who has.

Jon

unread,
Jun 18, 2009, 6:48:24 AM6/18/09
to Google Safe Browsing API
> I have never been able to get this to work, I have never seen anyone on here
> who has.

I managed to get this working. My problem was that I was hexadecimal-
encoding the data before running the hash when I should've run the
hash on the raw bytes.

Thanks.
Reply all
Reply to author
Forward
0 new messages