<?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[Crypto++]]></title><description><![CDATA[<p>Abend</p>
<p>Ich hab mich etwas mit der Crypto++ Library auseinader gesetzt und habe gemerkt, dass ich schnell an meine Grenzen gestoßen bin, da die Dokumentation für meine Begriffe recht dürftig ist.</p>
<p>Wenn ich mit dem erstellten Programm Dateien, welche größer als ca. 3Kb sind, verschlüssel (egal, wieviel bit der Schlüssel hat) kommt es zu einem Programmabsturz mit folgender Meldung:<br />
<a href="http://img140.imageshack.us/my.php?image=screenshootwe0.png" rel="nofollow">http://img140.imageshack.us/my.php?image=screenshootwe0.png</a></p>
<p>Es liegt sehr nahe, dass ich irgendwelche wichtigen Parameter vergessen habe, die mir den Umgang mit größeren Dateien ermöglichen.</p>
<p>Wie gesagt, bei Dateien &lt; 3KB funktioniert das Programm tadellos.</p>
<pre><code class="language-cpp">#ifdef _DEBUG
#pragma comment (lib, &quot;cryptlibd&quot;)
#else
#pragma comment (lib, &quot;cryptlib&quot;)
#endif

#include &lt;rsa.h&gt;
#include &lt;hex.h&gt;
#include &lt;files.h&gt;
#include &lt;osrng.h&gt;

#include &lt;iostream&gt;
#include &lt;cstring&gt;

bool generate_keys(const std::string&amp; public_key_file_name,
				   const std::string&amp; private_key_file_name,
				   unsigned long bits)
{
	// Zufallszahlengenerator
	CryptoPP::AutoSeededRandomPool rng;

	// Schlüsselerzeugung
	// privater Schlüssel
	CryptoPP::RSAES_OAEP_SHA_Decryptor decryptor(rng, bits);
	CryptoPP::HexEncoder private_file(new CryptoPP::FileSink(private_key_file_name.c_str()));

	decryptor.DEREncode(private_file);
	private_file.MessageEnd();

	// öffentlicher Schlüssel
	CryptoPP::RSAES_OAEP_SHA_Encryptor encryptor(decryptor);
	CryptoPP::HexEncoder public_file(new CryptoPP::FileSink(public_key_file_name.c_str()));

	encryptor.DEREncode(public_file);
	public_file.MessageEnd();

	// TODO: prüfen, ob Keys erstellt wurden

	return(true);
}

bool encrypt_file(const std::string&amp; public_key_file_name, 
				  const std::string&amp; source_file_name,
				  const std::string&amp; destination_file_name)
{
	// TODO: prüfen, ob Key existiert
	// TODO: prüfen, ob Key gültig ist
	// TODO: prüfen, ob Quelldatei existiert
	// TODO: prüfen, ob Verschlüsslung erfolgreich war

	// Schlüssel laden
	CryptoPP::FileSource public_file(public_key_file_name.c_str(), true, new CryptoPP::HexDecoder);
	CryptoPP::RSAES_OAEP_SHA_Encryptor encryptor(public_file);
	// Zufallszahlengenerator
	CryptoPP::AutoSeededRandomPool rng;

	// Zieldatei laden, Verschlüsseln und in Quelldatei abspeichern
	CryptoPP::FileSource(source_file_name.c_str(), true, new 
						 CryptoPP::PK_EncryptorFilter(rng, encryptor, 
						 new CryptoPP::HexEncoder(new CryptoPP::FileSink(destination_file_name.c_str()))));

	return(true);
}

bool decrypt_file(const std::string&amp; private_key_file_name, 
				  const std::string&amp; source_file_name,
				  const std::string&amp; destination_file_name)
{
	// TODO: prüfen, ob Key existiert
	// TODO: prüfen, ob Key gültig ist
	// TODO: prüfen, ob Quelldatei existiert
	// TODO: prüfen, ob Entschlüsslung erfolgreich war

	CryptoPP::FileSource private_file(private_key_file_name.c_str(), true, new CryptoPP::HexDecoder);
	CryptoPP::RSAES_OAEP_SHA_Decryptor decryptor(private_file);

	// Zufallszahlengenerator
	CryptoPP::AutoSeededRandomPool rng;
	// Zieldatei laden, Entschlüsseln und in Quelldatei abspeichern
	CryptoPP::FileSource(source_file_name.c_str(), true, new CryptoPP::HexDecoder(new CryptoPP::PK_DecryptorFilter(rng, decryptor, new CryptoPP::FileSink(destination_file_name.c_str()))));

	return(true);
}

/*
bool encrypt_string(const std::string&amp; public_key_file_name, 
				  const std::string&amp; source_file_name,
				  const std::string&amp; destination_file_name)
{
	return(false);
}

bool decrypt_string(const std::string&amp; private_key_file_name, 
				  const std::string&amp; source_file_name,
				  const std::string&amp; destination_file_name)
{
	return(false);
}
*/

int main(void)
{
	int choice;
	while(1)
	{
		std::cout &lt;&lt; &quot;\n[0] - cancel\n&quot; 
				  &lt;&lt; &quot;[1] - generate keys\n&quot;
				  &lt;&lt; &quot;[2] - encnryt Message\n&quot;
				  &lt;&lt; &quot;[3] - decrypt Message\n&quot;
				  &lt;&lt; &quot;[4] - help\n&quot;;

		std::cin &gt;&gt; choice;

		switch(choice)
		{
			// Beenden
		case 0:
			return 0;

			// Schlüssel erzeugen
		case 1:
			{
				std::string pbkf, pvkf;
				unsigned long key_strength;

				std::cout &lt;&lt; &quot;path and name of the public key file\n&quot;;
				std::cin &gt;&gt; pbkf;
				std::cout &lt;&lt; &quot;path and name of the private key file\n&quot;;
				std::cin &gt;&gt; pvkf;
				std::cout &lt;&lt; &quot;key strength in bits; recommended values[1024, 2048, 4092, 8192, 16384]\n&quot;;
				std::cin &gt;&gt; key_strength;

				generate_keys(pbkf, pvkf, key_strength);

				std::cout &lt;&lt; &quot;keys were created successfully\n&quot;;

				break;
			}

			// Verschlüsseln
		case 2:
			{
				std::string pbkf, sf, df;

				std::cout &lt;&lt; &quot;path and name of the public key file\n&quot;;
				std::cin &gt;&gt; pbkf;
				std::cout &lt;&lt; &quot;path and name of the source file\n&quot;;
				std::cin &gt;&gt; sf;
				std::cout &lt;&lt; &quot;path and name of the destination file\n&quot;;
				std::cin &gt;&gt; df;

				encrypt_file(pbkf, sf, df);

				std::cout &lt;&lt; &quot;file were encrypted successfully\n&quot;;

				break;
			}

			// Entschlüsseln
		case 3:
			{
				std::string pvkf, sf, df;

				std::cout &lt;&lt; &quot;path and name of the private key file\n&quot;;
				std::cin &gt;&gt; pvkf;
				std::cout &lt;&lt; &quot;path and name of the source file\n&quot;;
				std::cin &gt;&gt; sf;
				std::cout &lt;&lt; &quot;path and name of the destination file\n&quot;;
				std::cin &gt;&gt; df;

				decrypt_file(pvkf, sf, df);

				std::cout &lt;&lt; &quot;file were decrypted successfully\n&quot;;

				break;
			}

		case 4:
			break;

		}
	}

	return 0;
}
</code></pre>
<p>MangaMan</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/228089/crypto</link><generator>RSS for Node</generator><lastBuildDate>Tue, 29 Sep 2026 17:24:28 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/228089.rss" rel="self" type="application/rss+xml"/><pubDate>Sun, 23 Nov 2008 21:21:45 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Crypto++ on Sun, 23 Nov 2008 21:21:45 GMT]]></title><description><![CDATA[<p>Abend</p>
<p>Ich hab mich etwas mit der Crypto++ Library auseinader gesetzt und habe gemerkt, dass ich schnell an meine Grenzen gestoßen bin, da die Dokumentation für meine Begriffe recht dürftig ist.</p>
<p>Wenn ich mit dem erstellten Programm Dateien, welche größer als ca. 3Kb sind, verschlüssel (egal, wieviel bit der Schlüssel hat) kommt es zu einem Programmabsturz mit folgender Meldung:<br />
<a href="http://img140.imageshack.us/my.php?image=screenshootwe0.png" rel="nofollow">http://img140.imageshack.us/my.php?image=screenshootwe0.png</a></p>
<p>Es liegt sehr nahe, dass ich irgendwelche wichtigen Parameter vergessen habe, die mir den Umgang mit größeren Dateien ermöglichen.</p>
<p>Wie gesagt, bei Dateien &lt; 3KB funktioniert das Programm tadellos.</p>
<pre><code class="language-cpp">#ifdef _DEBUG
#pragma comment (lib, &quot;cryptlibd&quot;)
#else
#pragma comment (lib, &quot;cryptlib&quot;)
#endif

#include &lt;rsa.h&gt;
#include &lt;hex.h&gt;
#include &lt;files.h&gt;
#include &lt;osrng.h&gt;

#include &lt;iostream&gt;
#include &lt;cstring&gt;

bool generate_keys(const std::string&amp; public_key_file_name,
				   const std::string&amp; private_key_file_name,
				   unsigned long bits)
{
	// Zufallszahlengenerator
	CryptoPP::AutoSeededRandomPool rng;

	// Schlüsselerzeugung
	// privater Schlüssel
	CryptoPP::RSAES_OAEP_SHA_Decryptor decryptor(rng, bits);
	CryptoPP::HexEncoder private_file(new CryptoPP::FileSink(private_key_file_name.c_str()));

	decryptor.DEREncode(private_file);
	private_file.MessageEnd();

	// öffentlicher Schlüssel
	CryptoPP::RSAES_OAEP_SHA_Encryptor encryptor(decryptor);
	CryptoPP::HexEncoder public_file(new CryptoPP::FileSink(public_key_file_name.c_str()));

	encryptor.DEREncode(public_file);
	public_file.MessageEnd();

	// TODO: prüfen, ob Keys erstellt wurden

	return(true);
}

bool encrypt_file(const std::string&amp; public_key_file_name, 
				  const std::string&amp; source_file_name,
				  const std::string&amp; destination_file_name)
{
	// TODO: prüfen, ob Key existiert
	// TODO: prüfen, ob Key gültig ist
	// TODO: prüfen, ob Quelldatei existiert
	// TODO: prüfen, ob Verschlüsslung erfolgreich war

	// Schlüssel laden
	CryptoPP::FileSource public_file(public_key_file_name.c_str(), true, new CryptoPP::HexDecoder);
	CryptoPP::RSAES_OAEP_SHA_Encryptor encryptor(public_file);
	// Zufallszahlengenerator
	CryptoPP::AutoSeededRandomPool rng;

	// Zieldatei laden, Verschlüsseln und in Quelldatei abspeichern
	CryptoPP::FileSource(source_file_name.c_str(), true, new 
						 CryptoPP::PK_EncryptorFilter(rng, encryptor, 
						 new CryptoPP::HexEncoder(new CryptoPP::FileSink(destination_file_name.c_str()))));

	return(true);
}

bool decrypt_file(const std::string&amp; private_key_file_name, 
				  const std::string&amp; source_file_name,
				  const std::string&amp; destination_file_name)
{
	// TODO: prüfen, ob Key existiert
	// TODO: prüfen, ob Key gültig ist
	// TODO: prüfen, ob Quelldatei existiert
	// TODO: prüfen, ob Entschlüsslung erfolgreich war

	CryptoPP::FileSource private_file(private_key_file_name.c_str(), true, new CryptoPP::HexDecoder);
	CryptoPP::RSAES_OAEP_SHA_Decryptor decryptor(private_file);

	// Zufallszahlengenerator
	CryptoPP::AutoSeededRandomPool rng;
	// Zieldatei laden, Entschlüsseln und in Quelldatei abspeichern
	CryptoPP::FileSource(source_file_name.c_str(), true, new CryptoPP::HexDecoder(new CryptoPP::PK_DecryptorFilter(rng, decryptor, new CryptoPP::FileSink(destination_file_name.c_str()))));

	return(true);
}

/*
bool encrypt_string(const std::string&amp; public_key_file_name, 
				  const std::string&amp; source_file_name,
				  const std::string&amp; destination_file_name)
{
	return(false);
}

bool decrypt_string(const std::string&amp; private_key_file_name, 
				  const std::string&amp; source_file_name,
				  const std::string&amp; destination_file_name)
{
	return(false);
}
*/

int main(void)
{
	int choice;
	while(1)
	{
		std::cout &lt;&lt; &quot;\n[0] - cancel\n&quot; 
				  &lt;&lt; &quot;[1] - generate keys\n&quot;
				  &lt;&lt; &quot;[2] - encnryt Message\n&quot;
				  &lt;&lt; &quot;[3] - decrypt Message\n&quot;
				  &lt;&lt; &quot;[4] - help\n&quot;;

		std::cin &gt;&gt; choice;

		switch(choice)
		{
			// Beenden
		case 0:
			return 0;

			// Schlüssel erzeugen
		case 1:
			{
				std::string pbkf, pvkf;
				unsigned long key_strength;

				std::cout &lt;&lt; &quot;path and name of the public key file\n&quot;;
				std::cin &gt;&gt; pbkf;
				std::cout &lt;&lt; &quot;path and name of the private key file\n&quot;;
				std::cin &gt;&gt; pvkf;
				std::cout &lt;&lt; &quot;key strength in bits; recommended values[1024, 2048, 4092, 8192, 16384]\n&quot;;
				std::cin &gt;&gt; key_strength;

				generate_keys(pbkf, pvkf, key_strength);

				std::cout &lt;&lt; &quot;keys were created successfully\n&quot;;

				break;
			}

			// Verschlüsseln
		case 2:
			{
				std::string pbkf, sf, df;

				std::cout &lt;&lt; &quot;path and name of the public key file\n&quot;;
				std::cin &gt;&gt; pbkf;
				std::cout &lt;&lt; &quot;path and name of the source file\n&quot;;
				std::cin &gt;&gt; sf;
				std::cout &lt;&lt; &quot;path and name of the destination file\n&quot;;
				std::cin &gt;&gt; df;

				encrypt_file(pbkf, sf, df);

				std::cout &lt;&lt; &quot;file were encrypted successfully\n&quot;;

				break;
			}

			// Entschlüsseln
		case 3:
			{
				std::string pvkf, sf, df;

				std::cout &lt;&lt; &quot;path and name of the private key file\n&quot;;
				std::cin &gt;&gt; pvkf;
				std::cout &lt;&lt; &quot;path and name of the source file\n&quot;;
				std::cin &gt;&gt; sf;
				std::cout &lt;&lt; &quot;path and name of the destination file\n&quot;;
				std::cin &gt;&gt; df;

				decrypt_file(pvkf, sf, df);

				std::cout &lt;&lt; &quot;file were decrypted successfully\n&quot;;

				break;
			}

		case 4:
			break;

		}
	}

	return 0;
}
</code></pre>
<p>MangaMan</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1619642</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1619642</guid><dc:creator><![CDATA[MangaMan]]></dc:creator><pubDate>Sun, 23 Nov 2008 21:21:45 GMT</pubDate></item></channel></rss>