但是我收到了这个错误:
非静态字段,方法或属性rsa需要对象引用
public string FingerPrint
{
get
{
byte[] bytes = Utility.GetBytes(Imagin.FingerPrint.CPUId);
byte[] encrypted_bytes = this.Encrypt(bytes, RSA.ExportParameters(false), false);
return Utility.GetString(encrypted_bytes);
}
}
public byte[] Encrypt(byte[] Data, RSAParameters RSAKey, bool DoOAEPPadding)
{
try
{
byte[] encryptedData;
using (RSACryptoServiceProvider RSA = new RSACryptoServiceProvider())
{
RSA.ImportParameters(RSAKey); encryptedData = RSA.Encrypt(Data, DoOAEPPadding);
}
return encryptedData;
}
catch (CryptographicException e)
{
Console.WriteLine(e.Message);
return null;
}
}
public byte[] Decrypt(byte[] Data, RSAParameters RSAKey, bool DoOAEPPadding)
{
try
{
byte[] decryptedData;
using (RSACryptoServiceProvider RSA = new RSACryptoServiceProvider())
{
RSA.ImportParameters(RSAKey);
decryptedData = RSA.Decrypt(Data, DoOAEPPadding);
}
return decryptedData;
}
catch (CryptographicException e)
{
Console.WriteLine(e.ToString());
return null;
}
}
我在另一篇文章中读到它是因为我需要使用一个新的对象实例:RSA.ExportParameters(false)
。什么的实例?我尝试在我的MainWindow构造函数中放置获取FingerPrint
的代码,但也没有运气。如果我将FingerPrint
设为静态,则只会产生更多问题。
我做得不好?