Unhandled Exception: System.Security.Cryptography.CryptographicException: Private/public key mismatch
at Mono.Security.Cryptography.RSAManaged.ImportParameters (RSAParameters parameters) [0x00000] in <filename unknown>:0
at System.Security.Cryptography.RSACryptoServiceProvider.ImportParameters (RSAParameters parameters) [0x00000] in <filename unknown>:0
at BlaBlaFunc() [0x00000] in <filename unknown>:0
[ERROR] FATAL UNHANDLED EXCEPTION: System.Security.Cryptography.CryptographicException: Private/public key mismatch
at Mono.Security.Cryptography.RSAManaged.ImportParameters (RSAParameters parameters) [0x00000] in <filename unknown>:0
at System.Security.Cryptography.RSACryptoServiceProvider.ImportParameters (RSAParameters parameters) [0x00000] in <filename unknown>:0
at BlaBlaFunc() [0x00000] in <filename unknown>:0
这是源代码:
string foo = "blabla";
System.Security.Cryptography.RSAParameters rsa_params = new System.Security.Cryptography.RSAParameters();
rsa_params.Modulus = Enumerable.Range(0, pubkey.Length)
.Where(x => x % 2 == 0)
.Select(x => System.Convert.ToByte(pubkey.Substring(x, 2), 16))
.ToArray();
rsa_params.Exponent = new byte[] { 1, 0, 1 };
System.Security.Cryptography.RSACryptoServiceProvider rsa = new System.Security.Cryptography.RSACryptoServiceProvider();
System.Security.Cryptography.RSAParameters d = rsa.ExportParameters(false);
rsa.ImportParameters(rsa_params);
byte[] sp = rsa.Encrypt(Encoding.UTF8.GetBytes(foo), false);
在 windows 下运行良好的 .exe 文件是用 vs2010 编译的。它在 Ubuntu 下使用 mono 运行。
使用以下命令运行:
mono --runtime=v4.0.30319 xxx.exe
我怎样才能解决这个问题?