using (Aes aes = Aes.Create())
{
aes.GenerateIV();
aes.GenerateKey();
byte[] input = Encoding.ASCII.GetBytes("HELLOWORLD");
byte[] output;
using (var encryptor = aes.CreateEncryptor())
{
output = encryptor.TransformFinalBlock(input, 0, input.Length);
Console.WriteLine("Key(BASE64):{0}", Convert.ToBase64String(aes.Key));
Console.WriteLine("Key(HEX):{0}", BitConverter.ToString(aes.Key));
Console.WriteLine("Secret(BASE64):{0}", Convert.ToBase64String(output));
Console.WriteLine("Secret(HEX):{0}", BitConverter.ToString(output));
}
aes.GenerateKey();
using (var encryptor = aes.CreateEncryptor())
{
output = encryptor.TransformFinalBlock(input, 0, input.Length);
Console.WriteLine("Key(BASE64):{0}", Convert.ToBase64String(aes.Key));
Console.WriteLine("Key(HEX):{0}", BitConverter.ToString(aes.Key));
Console.WriteLine("Secret(BASE64):{0}", Convert.ToBase64String(output));
Console.WriteLine("Secret(HEX):{0}", BitConverter.ToString(output));
}
using (var decryptor = aes.CreateDecryptor())
{
byte[] dec = decryptor.TransformFinalBlock(output, 0, output.Length);
Console.WriteLine("PLAIN:{0}", Encoding.ASCII.GetString(dec));
}
}
Console.ReadKey();
这个应该是你的代码问题。
你好!
肯定是程序的问题,没有代码怎么知道原因