C# 在C语言上使用AES解码的问题#

C# 在C语言上使用AES解码的问题#,c#,aes,string-decoding,C#,Aes,String Decoding,嗨,伙计们,我在解码我的文本时遇到了问题,当我想要解码VS调试器时,它会告诉我“输入数据不是一个完整的块。” 我尝试了各种方法来解决此问题,但找不到:( 有人能帮我吗? 谢谢 //编码 尝试 { MD5CryptoServiceProvider md5=新的MD5CryptoServiceProvider(); UTF8Encoding utf8=新的UTF8Encoding(); AESCryptServiceProvider aes=新的AESCryptServiceProvider();

嗨,伙计们,我在解码我的文本时遇到了问题,当我想要解码VS调试器时,它会告诉我“输入数据不是一个完整的块。” 我尝试了各种方法来解决此问题,但找不到:( 有人能帮我吗? 谢谢

//编码
尝试
{
MD5CryptoServiceProvider md5=新的MD5CryptoServiceProvider();
UTF8Encoding utf8=新的UTF8Encoding();
AESCryptServiceProvider aes=新的AESCryptServiceProvider();
aes.KeySize=256;
aes.BlockSize=128;
string str=System.IO.File.ReadAllText(pathread);
aes.IV=md5.ComputeHash(utf8.GetBytes(textBox3.Text));
aes.Key=md5.ComputeHash(utf8.GetBytes(textBox4.Text));
aes.Mode=System.Security.Cryptography.CipherMode.CBC;
aes.Padding=System.Security.Cryptography.PaddingMode.PKCS7;
ICryptoTransform ic2=aes.CreateEncryptor();
字节[]enc=ic2.TransformFinalBlock(utf8.GetBytes(str),0,utf8.GetBytes(str).Length);
richTextBox1.Text=位转换器.ToString(enc);
//字符串toraj=BitConverter.ToString(ic2.TransformFinalBlock(utf8.GetBytes(str)、0、utf8.GetBytes(str.Length));
}
捕获(异常e1)
{
MessageBox.Show(e1.Message,“Error”,MessageBoxButtons.OK,MessageBoxIcon.Information);
}
//解码
MD5CryptoServiceProvider md5=新的MD5CryptoServiceProvider();
UTF8Encoding utf8=新的UTF8Encoding();
AESCryptServiceProvider aes=新的AESCryptServiceProvider();
aes.KeySize=256;
aes.BlockSize=128;
string str=richTextBox1.Text.ToString();
aes.IV=md5.ComputeHash(utf8.GetBytes(textBox3.Text));
aes.Key=md5.ComputeHash(utf8.GetBytes(textBox4.Text));
aes.Mode=System.Security.Cryptography.CipherMode.CBC;
MessageBox.Show(str);
byte[]encrypted=Encoding.UTF8.GetBytes(str);
aes.Padding=System.Security.Cryptography.PaddingMode.PKCS7;
ICryptoTransform ic5=aes.CreateDecryptor();
//对于(int x=0;x
这是将字节写入文本框

utf8.GetBytes(richTextBox1.Text)

你真的认为这会产生相同的字节吗?使用调试器,在加密和解密字节数组之前检查两个字节数组。然后找到一种方法来存储字节数组而不更改它。你可以单独存储它,也可以更改将其写入e textbox或您可以更改从文本框中读取文本的例行程序。选择您最喜欢的一个。

谢谢,我考虑过了,所以我应该使用拆分将所有文本分开,并将它们添加到列表或其他内容中?是吗?是的,这会起作用。可能是像
var bytes=richTextBox1.Text.split('-')这样简单的内容。选择(byte.Parse).ToArray()
richTextBox1.Text = BitConverter.ToString(enc);
utf8.GetBytes(richTextBox1.Text)