我从xml获取字符串时遇到问题。在xml中,我有RSACryptoServiceProvider
所以这是我生成RSA的代码,我将其保存到文件中:
RSACryptoServiceProvider rsa = new RSACryptoServiceProvider(LENGHT_OF_KEY);
var public_key = rsa.ToXmlString(false); // RSA.FromXmlString(publicKey);
using (StreamWriter sw = new StreamWriter(public_keys_path + name, true))
{
sw.Write(public_key);
sw.Flush();
sw.Close();
}
然后我尝试从文件中获取密钥,然后将其转换为字符串:
using (StreamReader sr = new StreamReader(public_keys_path.ToString() + user))
{
String public_keyXML = sr.ReadToEnd();
String public_key = rsa.FromXmlString(public_keyXML); // here i get the error
}
我收到错误:
“无法将类型'void'隐式转换为'string'。”
即使方法FromXmlString
返回一个字符串!这对我来说没有意义。我做错了什么?