J'ai besoin d'implémenter un protocole cryptographique sur C# et je veux dire que c'est mon premier projet en C#. Après avoir passé du temps à m'habituer à C#, j'ai découvert que je ne pouvais pas obtenir des vecteurs AES conformes..NET AES renvoie faux Vecteurs de test
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Security.Cryptography;
using System.IO;
namespace ConsoleApplication1
{
class Program
{
public static void Main()
{
try
{
byte[] key = { 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
byte[] data = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
byte[] encTest = { 0x0e, 0xdd, 0x33, 0xd3, 0xc6, 0x21, 0xe5, 0x46, 0x45, 0x5b, 0xd8, 0xba, 0x14, 0x18, 0xbe, 0xc8 };
AesManaged aesAlg = new AesManaged();
aesAlg.BlockSize = 128;
aesAlg.Key = key;
aesAlg.Mode = CipherMode.ECB;
aesAlg.Padding = PaddingMode.None;
ICryptoTransform encryptor = aesAlg.CreateEncryptor();
MemoryStream msEncrypt = new MemoryStream();
CryptoStream csEncrypt = new CryptoStream(msEncrypt, encryptor, CryptoStreamMode.Write);
csEncrypt.Write(data, 0,data.Length);
byte[] encr;
encr = msEncrypt.ToArray();
string datastr = BitConverter.ToString(data);
string encrstr = BitConverter.ToString(encr);
string encTestStr = BitConverter.ToString(encTest);
Console.WriteLine("data: {0}", datastr);
Console.WriteLine("encr: {0}", encrstr);
Console.WriteLine("should: {0}", encTestStr);
Console.ReadKey();
}
catch (Exception e)
{
Console.WriteLine("Error: {0}", e.Message);
}
}
}
}
sortie est erroné:
data: 00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00
encr: A0-3C-C2-22-A4-32-F7-C9-BA-36-AE-73-66-BD-BB-A3
should: 0E-DD-33-D3-C6-21-E5-46-45-5B-D8-BA-14-18-BE-C8
Je suis sûr qu'il ya une implémentation AES correcte dans .NET, donc j'ai besoin des conseils d'un assistant .NET pour aider.
EDIT
Je viens de le découvrir. Il doit PaddingMode.None, puis fonctionne. J'ai collé le code de travail. Merci quand même.
C# n'a pas d'implémentation AES. Le .NET Framework a une implémentation AES. –