2 * viking -- GPS Data and Topo Analyzer, Explorer, and Manager
4 * Copyright (C) 2016 Rob Norris <rw_norris@hotmail.com>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 #include <glib/gstdio.h>
29 #include <nettle/md5-compat.h>
33 * Get MD5 hash of a string using a library function
35 char *md5_hash(const char *message)
39 unsigned char result[16];
42 MD5Update ( &ctx, (const unsigned char*)message, strlen(message) );
43 MD5Final ( &result[0], &ctx );
45 g_printf ( "%s: of string '%s' is: ", __FUNCTION__, message );
46 for(int i = 0; i < 16; i++)
47 g_printf ( "%02x", result[i]);
50 // Should be nicer way of converting this but I can't think of one ATM
51 answer = g_strdup_printf ( "%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x",
52 result[0],result[1],result[2],result[3],result[4],result[5],result[6],result[7],
53 result[8],result[9],result[10],result[11],result[12],result[13],result[14],result[15]);
55 // Return something that might vaguely work in case you've disabled MD5 support
56 // but you should know what you've doing and uses of it (such as thumbnail caching) now won't work well
57 guint value = g_str_hash ( message );
58 answer = g_strdup_printf ( "%d", value );