Note that there are some explanatory texts on larger screens.

plurals
  1. POC# AES CBC wrong result
    text
    copied!<p>I'm trying to encrypt (AES) some data using C#.</p> <p>However I am getting a different result compared to a website: <a href="http://www.phpaes.com/index.php#encrypt" rel="nofollow">http://www.phpaes.com/index.php#encrypt</a></p> <p>Testdata:</p> <pre><code>Key = "abcdef1234567890" IV = "1234567890abcdef" Text = "test" </code></pre> <p>My C# code looks like this:</p> <pre><code>using System; using System.IO; using System.Security.Cryptography; using System.Text; namespace Test { class Program { public static void Main() { try { using (AesCryptoServiceProvider aes = new AesCryptoServiceProvider()) { aes.Mode = CipherMode.CBC; aes.Key = Encoding.UTF8.GetBytes("abcdef1234567890"); aes.IV = Encoding.UTF8.GetBytes("1234567890abcdef"); ICryptoTransform encryptor = aes.CreateEncryptor(); using (MemoryStream msEncrypt = new MemoryStream()) { using (CryptoStream csEncrypt = new CryptoStream(msEncrypt, encryptor, CryptoStreamMode.Write)) { using (StreamWriter swEncrypt = new StreamWriter(csEncrypt)) { swEncrypt.Write(Encoding.UTF8.GetBytes("test")); } byte[] encrypted = msEncrypt.ToArray(); Console.WriteLine(Convert.ToBase64String(encrypted)); } } Console.ReadKey(); } } catch (Exception e) { Console.WriteLine("Error: {0}", e.Message); } } } } </code></pre> <p>Results: (Base64)</p> <p>C#-Program: nhb34JyWvhiqiz8Gq9Z/kA==</p> <p>Website: 8jbduVNSb0Cz4cF+Cm9pCw==</p> <p>Why is that? Does it have to do with encodings? Is there something I forgot to add to the code? Thanks.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload