<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[string als MD5-Hash ausgeben...]]></title><description><![CDATA[<p>Hab ein code gefunden der dateien öffnet und dann den MD5 Hash Wert der datei anzeigt:</p>
<pre><code class="language-cpp">string MD5(string file)
{
	#define FILE_BUF_SIZE 1024
	#define HT_MD5     4

	int hashes = 0; 
	char *fname = NULL;                // will point to filename specified in argv
	FILE *f = NULL;                    // file access
	unsigned char buf[FILE_BUF_SIZE];  // file access
	unsigned int bytesread;            // file access

	MD5_CTX val_md5;  
	unsigned char md5digest[16];

	MD5Init(&amp;val_md5);

	hashes |= HT_MD5;

	fname = cvt.StringToChar(file);

	if ((f = fopen(fname, &quot;rb&quot;)) != NULL)
	{
		do
		{
			// reading to buffer
			bytesread = fread(buf, 1, FILE_BUF_SIZE, f);

			// updating hash vars
			if (hashes &amp; HT_MD5) MD5Update(&amp;val_md5, buf, bytesread);
		}
		while (bytesread == FILE_BUF_SIZE);
		fclose(f);
	} 
	else 
	{
		string str = &quot;Fehler: Auf Datei &lt;&quot; + file + &quot;&gt; kann nicht zugegriffen werden!&quot;;
		return str;
	}	

	MD5Final(md5digest, &amp;val_md5);

	string str;

	if (hashes &amp; HT_MD5)
	{
		MD5ToString((char *)md5digest, (char *)buf);
		//printf(&quot;MD5 = %s\n&quot;, buf);
		str = &quot;MD5 = &quot;;
		str += (char*)buf;
		return str;
	}
	return str;
}
</code></pre>
<p>...Doch ich möchte nur das ich ein normalen string in ein MD5 Hash wert umwandeln wie z.B. string s = &quot;test&quot; &lt;--- diesen string als Hash wert haben, ist das möglich mit der obigen funktion.</p>
<p>PS. Es gibt noch die md5.h</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/159116/string-als-md5-hash-ausgeben</link><generator>RSS for Node</generator><lastBuildDate>Tue, 21 Jul 2026 09:39:43 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/159116.rss" rel="self" type="application/rss+xml"/><pubDate>Tue, 12 Sep 2006 09:19:32 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to string als MD5-Hash ausgeben... on Tue, 12 Sep 2006 09:19:32 GMT]]></title><description><![CDATA[<p>Hab ein code gefunden der dateien öffnet und dann den MD5 Hash Wert der datei anzeigt:</p>
<pre><code class="language-cpp">string MD5(string file)
{
	#define FILE_BUF_SIZE 1024
	#define HT_MD5     4

	int hashes = 0; 
	char *fname = NULL;                // will point to filename specified in argv
	FILE *f = NULL;                    // file access
	unsigned char buf[FILE_BUF_SIZE];  // file access
	unsigned int bytesread;            // file access

	MD5_CTX val_md5;  
	unsigned char md5digest[16];

	MD5Init(&amp;val_md5);

	hashes |= HT_MD5;

	fname = cvt.StringToChar(file);

	if ((f = fopen(fname, &quot;rb&quot;)) != NULL)
	{
		do
		{
			// reading to buffer
			bytesread = fread(buf, 1, FILE_BUF_SIZE, f);

			// updating hash vars
			if (hashes &amp; HT_MD5) MD5Update(&amp;val_md5, buf, bytesread);
		}
		while (bytesread == FILE_BUF_SIZE);
		fclose(f);
	} 
	else 
	{
		string str = &quot;Fehler: Auf Datei &lt;&quot; + file + &quot;&gt; kann nicht zugegriffen werden!&quot;;
		return str;
	}	

	MD5Final(md5digest, &amp;val_md5);

	string str;

	if (hashes &amp; HT_MD5)
	{
		MD5ToString((char *)md5digest, (char *)buf);
		//printf(&quot;MD5 = %s\n&quot;, buf);
		str = &quot;MD5 = &quot;;
		str += (char*)buf;
		return str;
	}
	return str;
}
</code></pre>
<p>...Doch ich möchte nur das ich ein normalen string in ein MD5 Hash wert umwandeln wie z.B. string s = &quot;test&quot; &lt;--- diesen string als Hash wert haben, ist das möglich mit der obigen funktion.</p>
<p>PS. Es gibt noch die md5.h</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1135676</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1135676</guid><dc:creator><![CDATA[kernel64]]></dc:creator><pubDate>Tue, 12 Sep 2006 09:19:32 GMT</pubDate></item><item><title><![CDATA[Reply to string als MD5-Hash ausgeben... on Tue, 12 Sep 2006 09:23:15 GMT]]></title><description><![CDATA[<p>MD5Update(&amp;val_md5, &quot;test&quot;, 4);</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1135680</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1135680</guid><dc:creator><![CDATA[tests]]></dc:creator><pubDate>Tue, 12 Sep 2006 09:23:15 GMT</pubDate></item><item><title><![CDATA[Reply to string als MD5-Hash ausgeben... on Tue, 12 Sep 2006 09:42:23 GMT]]></title><description><![CDATA[<p>Danke für die schnelle Hilfe <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f603.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--grinning_face_with_big_eyes"
      title=":D"
      alt="😃"
    /></p>
<p>Beim zweiten Parameter wird ein 'unsigned char *' erwartet, wie kann ich ein string<br />
hier umwandeln damit es funktioniert?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1135701</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1135701</guid><dc:creator><![CDATA[kernel64]]></dc:creator><pubDate>Tue, 12 Sep 2006 09:42:23 GMT</pubDate></item><item><title><![CDATA[Reply to string als MD5-Hash ausgeben... on Tue, 12 Sep 2006 09:58:32 GMT]]></title><description><![CDATA[<p>Mit</p>
<pre><code class="language-cpp">string MeinString;
MeinString.c_str();
</code></pre>
<p>bekommst einen const char *.<br />
wahrscheinlich nimmt er ihn nicht an drum buffer allozieren rein schreiben und dann den buffer übergeben :D. <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f609.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--winking_face"
      title=";)"
      alt="😉"
    /></p>
]]></description><link>https://www.c-plusplus.net/forum/post/1135717</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1135717</guid><dc:creator><![CDATA[tobZel]]></dc:creator><pubDate>Tue, 12 Sep 2006 09:58:32 GMT</pubDate></item><item><title><![CDATA[Reply to string als MD5-Hash ausgeben... on Tue, 12 Sep 2006 10:05:33 GMT]]></title><description><![CDATA[<p>reinterpret_cast&lt;unsigned char*&gt;(&quot;test&quot;)</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1135723</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1135723</guid><dc:creator><![CDATA[rei]]></dc:creator><pubDate>Tue, 12 Sep 2006 10:05:33 GMT</pubDate></item><item><title><![CDATA[Reply to string als MD5-Hash ausgeben... on Tue, 12 Sep 2006 10:06:33 GMT]]></title><description><![CDATA[<p>Da haste Recht mit MeinString.c_str();</p>
<p>Hab es so gelöst:</p>
<pre><code class="language-cpp">char test[50];
			strcpy(test, file.c_str());
			if (hashes &amp; HT_MD5) MD5Update(&amp;val_md5, (unsigned char*)test, file.length());
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1135724</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1135724</guid><dc:creator><![CDATA[kernel64]]></dc:creator><pubDate>Tue, 12 Sep 2006 10:06:33 GMT</pubDate></item></channel></rss>