<?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[AES liefert in C# andere Ergebnisse als in PHP]]></title><description><![CDATA[<p>Hi,</p>
<p>ich möchte den Rijndael-Algo in C# und PHP benutzen. Leider bekomme ich verschiedene Ergebnisse.</p>
<p>Hier der C#-Code:</p>
<pre><code>using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Collections;
using System.IO;
using System.Security.Cryptography;

        public string encryptString(string text, string key, string iv)
        {
            Rijndael rij = Rijndael.Create();
            rij.Mode = CipherMode.CBC;
            rij.KeySize = 256;
            rij.BlockSize = 256;
            rij.Key = Encoding.ASCII.GetBytes(key);
            rij.IV = Encoding.ASCII.GetBytes(iv);

            ICryptoTransform ct;
            MemoryStream ms;
            CryptoStream cs;
            byte[] byt;
            ct = rij.CreateEncryptor(rij.Key, rij.IV);
            byt = Encoding.UTF8.GetBytes(text);            
            ms = new MemoryStream();
            cs = new CryptoStream(ms, ct, CryptoStreamMode.Write);
            cs.Write(byt, 0, byt.Length);
            cs.FlushFinalBlock();
            cs.Close();
            return Convert.ToBase64String(ms.ToArray());         
        }

        private void button2_Click(object sender, EventArgs e)
        {
            MessageBox.Show(encryptString(textBox1.Text, &quot;aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa&quot;, &quot;11111111111111111111111111111111&quot;));           
        }
</code></pre>
<p>und hier der PHP-Code:</p>
<pre><code>&lt;?php
$myAES = new AES();
echo $myAES-&gt;Encrypt(&quot;test&quot;);

class AES {
    var $password = &quot;aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa&quot;;

    public function Encrypt($text) {
        $iv_size = mcrypt_get_iv_size(MCRYPT_RIJNDAEL_256, MCRYPT_MODE_CBC); //get vector size on CBC mode		
        $iv = &quot;11111111111111111111111111111111&quot;; //Creating the vector
        $cryptedpass = mcrypt_encrypt (MCRYPT_RIJNDAEL_256, $this-&gt;password, $text, MCRYPT_MODE_CBC, $iv); //Encrypting using MCRYPT_RIJNDAEL_256 algorithm
		return base64_encode($cryptedpass);	
    }
}
?&gt;
</code></pre>
<p>Ich habe schon verschiedene Encodings im C#-Code durchprobiert. Ohne Erfolg. Ich komme immer auf unterschiedliche Ergebnisse.</p>
<p>Eins fällt natürlich sofort auf. In PHP benutze ich als IV einen 32 Zeichen langen String. In PHP mache ich aus einem 32 Zeichen langen String ein Byte-Array. Ich weiß aber nicht, wie ich das anders machen soll.</p>
<p>Wo liegt mein Fehler?</p>
<p>Danke für Eure Hilfe.</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/205224/aes-liefert-in-c-andere-ergebnisse-als-in-php</link><generator>RSS for Node</generator><lastBuildDate>Sat, 27 Jun 2026 19:31:21 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/205224.rss" rel="self" type="application/rss+xml"/><pubDate>Mon, 11 Feb 2008 20:58:19 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to AES liefert in C# andere Ergebnisse als in PHP on Mon, 11 Feb 2008 20:58:19 GMT]]></title><description><![CDATA[<p>Hi,</p>
<p>ich möchte den Rijndael-Algo in C# und PHP benutzen. Leider bekomme ich verschiedene Ergebnisse.</p>
<p>Hier der C#-Code:</p>
<pre><code>using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Collections;
using System.IO;
using System.Security.Cryptography;

        public string encryptString(string text, string key, string iv)
        {
            Rijndael rij = Rijndael.Create();
            rij.Mode = CipherMode.CBC;
            rij.KeySize = 256;
            rij.BlockSize = 256;
            rij.Key = Encoding.ASCII.GetBytes(key);
            rij.IV = Encoding.ASCII.GetBytes(iv);

            ICryptoTransform ct;
            MemoryStream ms;
            CryptoStream cs;
            byte[] byt;
            ct = rij.CreateEncryptor(rij.Key, rij.IV);
            byt = Encoding.UTF8.GetBytes(text);            
            ms = new MemoryStream();
            cs = new CryptoStream(ms, ct, CryptoStreamMode.Write);
            cs.Write(byt, 0, byt.Length);
            cs.FlushFinalBlock();
            cs.Close();
            return Convert.ToBase64String(ms.ToArray());         
        }

        private void button2_Click(object sender, EventArgs e)
        {
            MessageBox.Show(encryptString(textBox1.Text, &quot;aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa&quot;, &quot;11111111111111111111111111111111&quot;));           
        }
</code></pre>
<p>und hier der PHP-Code:</p>
<pre><code>&lt;?php
$myAES = new AES();
echo $myAES-&gt;Encrypt(&quot;test&quot;);

class AES {
    var $password = &quot;aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa&quot;;

    public function Encrypt($text) {
        $iv_size = mcrypt_get_iv_size(MCRYPT_RIJNDAEL_256, MCRYPT_MODE_CBC); //get vector size on CBC mode		
        $iv = &quot;11111111111111111111111111111111&quot;; //Creating the vector
        $cryptedpass = mcrypt_encrypt (MCRYPT_RIJNDAEL_256, $this-&gt;password, $text, MCRYPT_MODE_CBC, $iv); //Encrypting using MCRYPT_RIJNDAEL_256 algorithm
		return base64_encode($cryptedpass);	
    }
}
?&gt;
</code></pre>
<p>Ich habe schon verschiedene Encodings im C#-Code durchprobiert. Ohne Erfolg. Ich komme immer auf unterschiedliche Ergebnisse.</p>
<p>Eins fällt natürlich sofort auf. In PHP benutze ich als IV einen 32 Zeichen langen String. In PHP mache ich aus einem 32 Zeichen langen String ein Byte-Array. Ich weiß aber nicht, wie ich das anders machen soll.</p>
<p>Wo liegt mein Fehler?</p>
<p>Danke für Eure Hilfe.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1453997</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1453997</guid><dc:creator><![CDATA[_ravel]]></dc:creator><pubDate>Mon, 11 Feb 2008 20:58:19 GMT</pubDate></item><item><title><![CDATA[Reply to AES liefert in C# andere Ergebnisse als in PHP on Tue, 12 Feb 2008 04:57:28 GMT]]></title><description><![CDATA[<p>hat sich erledigt.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1454089</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1454089</guid><dc:creator><![CDATA[_ravel]]></dc:creator><pubDate>Tue, 12 Feb 2008 04:57:28 GMT</pubDate></item><item><title><![CDATA[Reply to AES liefert in C# andere Ergebnisse als in PHP on Tue, 12 Feb 2008 08:10:53 GMT]]></title><description><![CDATA[<p>worin lag der Unterschied?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1454139</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1454139</guid><dc:creator><![CDATA[Blue-Tiger]]></dc:creator><pubDate>Tue, 12 Feb 2008 08:10:53 GMT</pubDate></item><item><title><![CDATA[Reply to AES liefert in C# andere Ergebnisse als in PHP on Tue, 12 Feb 2008 14:08:30 GMT]]></title><description><![CDATA[<p>man muss in c# das padding vom rijndael-objekt auf zeros setzen. hab ich in der hinterletzten ecke der internets gefunden...</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1454430</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1454430</guid><dc:creator><![CDATA[_ravel]]></dc:creator><pubDate>Tue, 12 Feb 2008 14:08:30 GMT</pubDate></item></channel></rss>