C#에서 일부 암호화 프로토콜을 구현해야하며 C#의 첫 번째 프로젝트라고 말하고 싶습니다. C#에서 익숙해 지려면 약간의 시간을 보낸 후에 필자는 AES 벡터를 준수 할 수 없다는 것을 알았습니다. 나는 .NET에서 올바른 AES 구현이 있음을 확신.NET AES가 잘못된 테스트 벡터를 반환 함
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
, 그래서 나는이에 도움이되는 .NET 마법사에서 몇 가지 조언이 필요합니다
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);
}
}
}
}
출력은 잘못된 것입니다.
수정
방금 알아 냈습니다. PaddingMode.None이 있고 작동합니다. 작업 코드를 붙여 넣었습니다. 어쨌든 고마워.
C#에는 AES 구현이 없습니다. .NET Framework에는 AES 구현이 있습니다. –