<?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++ aes 128 cbc decrypt und iv problem]]></title><description><![CDATA[<p>Hallo liebe Programmierer!</p>
<p>Bin neu hier und quäle euch auch gleich mit meinem Problem. Versuche ein kleines Tool zu schreiben, welches AES-128-CBC mit iv verschlüsselte Strings entschlüsseln kann. iv ist immer konstant und zwar die ersten 16 bytes des verschlüsselten Strings. Im Grunde soll die Bedienung quasi &quot;aes -c ichbinverschluesseltertextinaes128cpwasuchimmerundsoweiterundsofort -p key&quot; sein. Da es unter Linux und Windows compiliert werden soll, habe ich mich für Crpyto++ entschieden. Arbeite mit der aktuellen Version 5.6.2 (<a href="https://www.cryptopp.com/#download" rel="nofollow">https://www.cryptopp.com/#download</a>).</p>
<p>1. Problem: Ich weiß leider nicht wie ich die ersten 16 Bytes des cipher Textes für das iv &quot;extrahieren&quot; soll.<br />
2. Problem: Die Syntax scheint mir generell noch Probleme zu machen.</p>
<p>Bin jetzt am Ende meiner Weisheit angekommen, einen Beispielcode habe ich zwar gefunden, aber der deckt leider nur einen Teil ab. Grundsätzlich habe ich <a href="https://cryptopp.com/w/images/b/bd/AES-CBC-Filter.zip" rel="nofollow">https://cryptopp.com/w/images/b/bd/AES-CBC-Filter.zip</a> zum laufen gebracht, aber &quot;random&quot; hilft mir nicht weiter.</p>
<p>Soweit bin ich gekommen:</p>
<pre><code>#include &lt;ctype.h&gt;
#include &lt;stdio.h&gt;
#include &lt;stdlib.h&gt;
#include &lt;unistd.h&gt;
#include &lt;iostream&gt;
using std::cout;
using std::cerr;
using std::endl;

#include &lt;string&gt;
using std::string;

#include &lt;cstdlib&gt;
using std::exit;

#include &quot;osrng.h&quot;
using CryptoPP::AutoSeededRandomPool;

#include &quot;cryptlib.h&quot;
using CryptoPP::Exception;

#include &quot;hex.h&quot;
using CryptoPP::HexEncoder;
using CryptoPP::HexDecoder;

#include &quot;filters.h&quot;
using CryptoPP::StringSink;
using CryptoPP::StringSource;
using CryptoPP::StreamTransformationFilter;

#include &quot;aes.h&quot;
using CryptoPP::AES;

#include &quot;ccm.h&quot;
using CryptoPP::CBC_Mode;

#include &quot;assert.h&quot;

int main (int argc, char **argv)
{
	int largs;
	char *myCypher = NULL;
	char *myPass = NULL;

	while ((largs = getopt (argc, argv, &quot;c:p:&quot;)) != -1)
	{
		switch (largs)
		{
			case 'c':
				myCypher = optarg;
			break;
			case 'p':
				myPass = optarg;
			break;
		}
	}

	if (myCypher == NULL || myPass == NULL)
	{
		exit(0);
	}

	string pass(myPass);
	string cipher(myCypher);
	byte key[16] = {pass};
	byte iv[16] = {cipher};
	string encoded, recovered;

	encoded.clear();
	StringSource(key, sizeof(key), true,
		new HexEncoder(
			new StringSink(encoded)
		) // HexEncoder
	); // StringSource
	cout &lt;&lt; &quot;key: &quot; &lt;&lt; encoded &lt;&lt; endl;

	encoded.clear();
	StringSource(iv, sizeof(iv), true,
		new HexEncoder(
			new StringSink(encoded)
		) // HexEncoder
	); // StringSource
	cout &lt;&lt; &quot;iv: &quot; &lt;&lt; encoded &lt;&lt; endl;

	// decrypt cypher
	try
	{
		CBC_Mode&lt; AES &gt;::Decryption d;
		d.SetKeyWithIV(key, sizeof(key), iv);

		// The StreamTransformationFilter removes
		//  padding as required.
		StringSource s(cipher, true, 
			new StreamTransformationFilter(d,
				new StringSink(recovered)
			) // StreamTransformationFilter
		); // StringSource

#if 0
		StreamTransformationFilter filter(d);
		filter.Put((const byte*)cipher.data(), cipher.size());
		filter.MessageEnd();

		const size_t ret = filter.MaxRetrievable();
		recovered.resize(ret);
		filter.Get((byte*)recovered.data(), recovered.size());
#endif

		cout &lt;&lt; &quot;recovered text: &quot; &lt;&lt; recovered &lt;&lt; endl;
	}
	catch(const CryptoPP::Exception&amp; e)
	{
		cerr &lt;&lt; e.what() &lt;&lt; endl;
		exit(1);
	}

	return 0;
}
</code></pre>
<p>Raus kommt dabei im Moment:</p>
<pre><code>g++ -I/home/crypto/aes/cryptopp562 aes.cpp -o aes -lcryptopp -lpthread
aes.cpp: In function ‘int main(int, char**)’:
aes.cpp:65:22: error: cannot convert ‘std::string {aka std::basic_string&lt;char&gt;}’ to ‘byte {aka unsigned char}’ in initialization
aes.cpp:66:23: error: cannot convert ‘std::string {aka std::basic_string&lt;char&gt;}’ to ‘byte {aka unsigned char}’ in initialization
</code></pre>
<p>Für jede Hilfe schon einmal den besten Dank im Voraus!</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/335337/crypto-aes-128-cbc-decrypt-und-iv-problem</link><generator>RSS for Node</generator><lastBuildDate>Fri, 24 Apr 2026 21:02:08 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/335337.rss" rel="self" type="application/rss+xml"/><pubDate>Sat, 14 Nov 2015 22:55:31 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to crypto++ aes 128 cbc decrypt und iv problem on Sat, 14 Nov 2015 22:55:31 GMT]]></title><description><![CDATA[<p>Hallo liebe Programmierer!</p>
<p>Bin neu hier und quäle euch auch gleich mit meinem Problem. Versuche ein kleines Tool zu schreiben, welches AES-128-CBC mit iv verschlüsselte Strings entschlüsseln kann. iv ist immer konstant und zwar die ersten 16 bytes des verschlüsselten Strings. Im Grunde soll die Bedienung quasi &quot;aes -c ichbinverschluesseltertextinaes128cpwasuchimmerundsoweiterundsofort -p key&quot; sein. Da es unter Linux und Windows compiliert werden soll, habe ich mich für Crpyto++ entschieden. Arbeite mit der aktuellen Version 5.6.2 (<a href="https://www.cryptopp.com/#download" rel="nofollow">https://www.cryptopp.com/#download</a>).</p>
<p>1. Problem: Ich weiß leider nicht wie ich die ersten 16 Bytes des cipher Textes für das iv &quot;extrahieren&quot; soll.<br />
2. Problem: Die Syntax scheint mir generell noch Probleme zu machen.</p>
<p>Bin jetzt am Ende meiner Weisheit angekommen, einen Beispielcode habe ich zwar gefunden, aber der deckt leider nur einen Teil ab. Grundsätzlich habe ich <a href="https://cryptopp.com/w/images/b/bd/AES-CBC-Filter.zip" rel="nofollow">https://cryptopp.com/w/images/b/bd/AES-CBC-Filter.zip</a> zum laufen gebracht, aber &quot;random&quot; hilft mir nicht weiter.</p>
<p>Soweit bin ich gekommen:</p>
<pre><code>#include &lt;ctype.h&gt;
#include &lt;stdio.h&gt;
#include &lt;stdlib.h&gt;
#include &lt;unistd.h&gt;
#include &lt;iostream&gt;
using std::cout;
using std::cerr;
using std::endl;

#include &lt;string&gt;
using std::string;

#include &lt;cstdlib&gt;
using std::exit;

#include &quot;osrng.h&quot;
using CryptoPP::AutoSeededRandomPool;

#include &quot;cryptlib.h&quot;
using CryptoPP::Exception;

#include &quot;hex.h&quot;
using CryptoPP::HexEncoder;
using CryptoPP::HexDecoder;

#include &quot;filters.h&quot;
using CryptoPP::StringSink;
using CryptoPP::StringSource;
using CryptoPP::StreamTransformationFilter;

#include &quot;aes.h&quot;
using CryptoPP::AES;

#include &quot;ccm.h&quot;
using CryptoPP::CBC_Mode;

#include &quot;assert.h&quot;

int main (int argc, char **argv)
{
	int largs;
	char *myCypher = NULL;
	char *myPass = NULL;

	while ((largs = getopt (argc, argv, &quot;c:p:&quot;)) != -1)
	{
		switch (largs)
		{
			case 'c':
				myCypher = optarg;
			break;
			case 'p':
				myPass = optarg;
			break;
		}
	}

	if (myCypher == NULL || myPass == NULL)
	{
		exit(0);
	}

	string pass(myPass);
	string cipher(myCypher);
	byte key[16] = {pass};
	byte iv[16] = {cipher};
	string encoded, recovered;

	encoded.clear();
	StringSource(key, sizeof(key), true,
		new HexEncoder(
			new StringSink(encoded)
		) // HexEncoder
	); // StringSource
	cout &lt;&lt; &quot;key: &quot; &lt;&lt; encoded &lt;&lt; endl;

	encoded.clear();
	StringSource(iv, sizeof(iv), true,
		new HexEncoder(
			new StringSink(encoded)
		) // HexEncoder
	); // StringSource
	cout &lt;&lt; &quot;iv: &quot; &lt;&lt; encoded &lt;&lt; endl;

	// decrypt cypher
	try
	{
		CBC_Mode&lt; AES &gt;::Decryption d;
		d.SetKeyWithIV(key, sizeof(key), iv);

		// The StreamTransformationFilter removes
		//  padding as required.
		StringSource s(cipher, true, 
			new StreamTransformationFilter(d,
				new StringSink(recovered)
			) // StreamTransformationFilter
		); // StringSource

#if 0
		StreamTransformationFilter filter(d);
		filter.Put((const byte*)cipher.data(), cipher.size());
		filter.MessageEnd();

		const size_t ret = filter.MaxRetrievable();
		recovered.resize(ret);
		filter.Get((byte*)recovered.data(), recovered.size());
#endif

		cout &lt;&lt; &quot;recovered text: &quot; &lt;&lt; recovered &lt;&lt; endl;
	}
	catch(const CryptoPP::Exception&amp; e)
	{
		cerr &lt;&lt; e.what() &lt;&lt; endl;
		exit(1);
	}

	return 0;
}
</code></pre>
<p>Raus kommt dabei im Moment:</p>
<pre><code>g++ -I/home/crypto/aes/cryptopp562 aes.cpp -o aes -lcryptopp -lpthread
aes.cpp: In function ‘int main(int, char**)’:
aes.cpp:65:22: error: cannot convert ‘std::string {aka std::basic_string&lt;char&gt;}’ to ‘byte {aka unsigned char}’ in initialization
aes.cpp:66:23: error: cannot convert ‘std::string {aka std::basic_string&lt;char&gt;}’ to ‘byte {aka unsigned char}’ in initialization
</code></pre>
<p>Für jede Hilfe schon einmal den besten Dank im Voraus!</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2475467</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2475467</guid><dc:creator><![CDATA[8Ohm]]></dc:creator><pubDate>Sat, 14 Nov 2015 22:55:31 GMT</pubDate></item><item><title><![CDATA[Reply to crypto++ aes 128 cbc decrypt und iv problem on Sun, 15 Nov 2015 13:18:27 GMT]]></title><description><![CDATA[<p>Wenn du schon mit diesem trivialen Problem überfordert bist, solltest du dich erst noch mal mit den C++ Grundlagen beschäftigen.</p>
<p>Warum quälst du die Werte überhaupt durch einen std::string? Du hast doch schon char Pointer, die kannst du beim Aufruf entsprechend casten.</p>
<p>Die Bibliothek scheint ja auch beschissen bis garnicht dokumentiert zu sein. Für einen Anfänger dürfte das wohl ziemlich schwierig werden.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2475520</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2475520</guid><dc:creator><![CDATA[manni66]]></dc:creator><pubDate>Sun, 15 Nov 2015 13:18:27 GMT</pubDate></item><item><title><![CDATA[Reply to crypto++ aes 128 cbc decrypt und iv problem on Sun, 15 Nov 2015 13:49:08 GMT]]></title><description><![CDATA[<p>Bitte nicht hinterfragen wieso und warum ich char zu strings mache, es war einfach nur Spielerei, die ebenfalls, wie alle anderen Versuche, gescheitert sind.</p>
<p>Wenn das Problem so trivial ist, wieso prostest du dann keine Lösung?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2475526</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2475526</guid><dc:creator><![CDATA[8Ohm]]></dc:creator><pubDate>Sun, 15 Nov 2015 13:49:08 GMT</pubDate></item><item><title><![CDATA[Reply to crypto++ aes 128 cbc decrypt und iv problem on Sun, 15 Nov 2015 18:26:49 GMT]]></title><description><![CDATA[<p>8Ohm schrieb:</p>
<blockquote>
<p>Wenn das Problem so trivial ist, wieso prostest du dann keine Lösung?</p>
</blockquote>
<p>Die beste Lösung, wäre deine &quot;Spielerei&quot; mit den Strings sein zu lassen, da sie absolut nutzlos ist und das Problem verursacht. Aber das dürfen wir ja nicht hinterfragen. Mit den Strings musst du eben eine lange Kette von C-String zu C++-String Konvertierungen schreiben, immer hin und her, je nach Bedarf. Die beiden sind halt absolut inkompatibel. Zuweisungen zueinander, als ob sie die gleiche Art von Objekt wären, gehen da nicht (abgesehen davon, dass Zuweisungen bei C-Strings generell nicht gehen).</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2475553</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2475553</guid><dc:creator><![CDATA[SeppJ]]></dc:creator><pubDate>Sun, 15 Nov 2015 18:26:49 GMT</pubDate></item><item><title><![CDATA[Reply to crypto++ aes 128 cbc decrypt und iv problem on Sun, 15 Nov 2015 21:42:37 GMT]]></title><description><![CDATA[<p>Bitte Herr Moderator, meinen Beitrag und User Account löschen. Sinnloses Forum.</p>
<p>Danke!</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2475575</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2475575</guid><dc:creator><![CDATA[8Ohm]]></dc:creator><pubDate>Sun, 15 Nov 2015 21:42:37 GMT</pubDate></item></channel></rss>