C# RSA.ImportRSAPrivateKey:System.PlatformNotSupportedException:此平台不支持操作
我得到一个C# RSA.ImportRSAPrivateKey:System.PlatformNotSupportedException:此平台不支持操作,c#,mono,rsa,C#,Mono,Rsa,我得到一个System.PlatformNotSupportedException:此平台上不支持操作System.Security.Cryptography.RSA.ImportRSAPrivateKey 这是我的密码: using System; using System.Security.Cryptography; using System.Text.RegularExpressions; class Test { static void Main() {
System.PlatformNotSupportedException:此平台上不支持操作System.Security.Cryptography.RSA.ImportRSAPrivateKey
这是我的密码:
using System;
using System.Security.Cryptography;
using System.Text.RegularExpressions;
class Test
{
static void Main()
{
var key = @"-----BEGIN RSA PRIVATE KEY-----
MIIBOgIBAAJBAKj34GkxFhD90vcNLYLInFEX6Ppy1tPf9Cnzj4p4WGeKLs1Pt8Qu
KUpRKfFLfRYC9AIKjbJTWit+CqvjWYzvQwECAwEAAQJAIJLixBy2qpFoS4DSmoEm
o3qGy0t6z09AIJtH+5OeRV1be+N4cDYJKffGzDa88vQENZiRm0GRq6a+HPGQMd2k
TQIhAKMSvzIBnni7ot/OSie2TmJLY4SwTQAevXysE2RbFDYdAiEBCUEaRQnMnbp7
9mxDXDf6AU0cN/RPBjb9qSHDcWZHGzUCIG2Es59z8ugGrDY+pxLQnwfotadxd+Uy
v/Ow5T0q5gIJAiEAyS4RaI9YG8EWx/2w0T67ZUVAw8eOMB6BIUg0Xcu+3okCIBOs
/5OiPgoTdSy7bcF9IGpSE8ZgGKzgYQVZeN97YE00
-----END RSA PRIVATE KEY-----";
Regex rx = new Regex(@"-+[^-]+-+");
key = rx.Replace(key, "")
.Replace("\r", "")
.Replace("\n", "");
var keyBytes = Convert.FromBase64String(key);
using var rsa = RSA.Create();
rsa.ImportRSAPrivateKey(keyBytes, out _);
}
}
以下是全部错误:
Unhandled Exception:
System.PlatformNotSupportedException: Operation is not supported on this platform.
at System.Security.Cryptography.RSA.ImportRSAPrivateKey (System.ReadOnlySpan`1[T] source, System.Int32& bytesRead) [0x00000] in <9f0df102fe6e4cfea29d2e46f585d8a5>:0
at Test.Main () [0x00051] in <49b14d77416941d28c91d3dba6162673>:0
[ERROR] FATAL UNHANDLED EXCEPTION: System.PlatformNotSupportedException: Operation is not supported on this platform.
at System.Security.Cryptography.RSA.ImportRSAPrivateKey (System.ReadOnlySpan`1[T] source, System.Int32& bytesRead) [0x00000] in <9f0df102fe6e4cfea29d2e46f585d8a5>:0
at Test.Main () [0x00051] in <49b14d77416941d28c91d3dba6162673>:0
Mono JIT compiler version 6.12.0.90 (tarball Fri Sep 4 14:01:23 UTC 2020)
Copyright (C) 2002-2014 Novell, Inc, Xamarin Inc and Contributors. www.mono-project.com
TLS: __thread
SIGSEGV: altstack
Notifications: epoll
Architecture: amd64
Disabled: none
Misc: softdebug
Interpreter: yes
LLVM: yes(610)
Suspend: hybrid
GC: sgen (concurrent by default)