C# 解密函数在c中不起作用#
我正在尝试编写一个“enrypt decrypt”程序,但解密函数有一些问题 不知何故,我无法将流读取器“ReadToEnd()”保存到名为“text”的空字符串中 我在互联网上找到了这个函数,我试图通过更改变量名和使用“IDisposed”而不是“using”来解决它。我无法解决它C# 解密函数在c中不起作用#,c#,encryption,cryptography,C#,Encryption,Cryptography,我正在尝试编写一个“enrypt decrypt”程序,但解密函数有一些问题 不知何故,我无法将流读取器“ReadToEnd()”保存到名为“text”的空字符串中 我在互联网上找到了这个函数,我试图通过更改变量名和使用“IDisposed”而不是“using”来解决它。我无法解决它 static string Decrypt(byte[] cipherText, byte[] Key, byte[] IV) { string text = String.Empty; // Cr
static string Decrypt(byte[] cipherText, byte[] Key, byte[] IV)
{
string text = String.Empty;
// Create an Aes object
// with the specified key and IV.
using (Aes aesAlg = Aes.Create())
{
aesAlg.Key = Key;
aesAlg.IV = IV;
// Create a decrytor to perform the stream transform.
ICryptoTransform decryptor = aesAlg.CreateDecryptor(aesAlg.Key, aesAlg.IV);
// Create the streams used for decryption.
using (MemoryStream msDecrypt = new MemoryStream(cipherText))
{
using (CryptoStream cs = new CryptoStream(msDecrypt, decryptor, CryptoStreamMode.Write))
{
using (StreamReader srDecrypt = new StreamReader(cs) )
{
// Read the decrypted bytes from the decrypting
stream
// and place them in a string.
text = srDecrypt.ReadToEnd();
}
}
}
}
return text;
}
文本字符串仅在此函数中定义,错误出现在以下行:
text=srDecrypt.ReadToEnd()
上面写着:
cs(145,29):错误CS0136:名为“text”的局部变量无法
在该范围内声明,因为它将赋予
“text”,已在“parent或current”范围中用于表示
其他编译失败:1个错误,0个警告
我认为您遗漏了一些代码,因为这是无效的:
// Read the decrypted bytes from the decrypting
stream
错误在哪一行?也将代码作为实际代码而不是图像发布。如果我必须猜一猜的话,这里有
string text=string.Empty()代码>,您的类中可能已经有一个名为text
的变量。在“stream”之后的代码中缺少一点内容,但如果您将代码(作为文本)发布,则会容易得多我想知道为什么这么多人喜欢发布代码和错误的图片,而不是代码和错误文本本身。也许这是一个元主题……但为什么会经常发生?@rory.ap可能是因为发布屏幕截图比复制粘贴代码并对其进行格式化更容易,这样看起来更漂亮。我同意仅仅发布屏幕截图是非常烦人和懒惰的。@Bas——拍摄屏幕截图,将其保存到您的计算机,将其粘贴到imagr站点,并包含它比复制/粘贴文本更容易??为什么不用手机拍张照片,发电子邮件给自己,下载,打印,扫描,保存,然后发布呢?你认为我应该在这之后添加什么?我没有错过代码粘贴在这里,就像我尝试删除这一行,然后你的代码应该被编译。