在Mono上使用X509Certificate2 – 使用公钥和私钥加载?
现在,我尝试像这样实例化X509Certificate2:
cert = new X509Certificate2(Resources.cred);
其中Resources.cred
是表示.pfx文件的byte[]
。
这在Windows / .NET上完全正常。
但是,在Mono JIT编译器版本3.2.8(Debian 3.2.8 + dfsg-4ubuntu1) (Ubuntu Server 14.04 LTS上的Mono )下运行相同的代码,我得到以下exception:
System.TypeInitializationException: An exception was thrown by the type initializer for ---> System.Security.Cryptography.CryptographicException: Unable to decode certificate. ---> System.Security.Cryptography.CryptographicException: Input data cannot be coded as a valid certificate. ---> System.Security.Cryptography.CryptographicException: Input data cannot be coded as a valid certificate. at Mono.Security.X509.X509Certificate.Parse (System.Byte[] data) [0x00000] in :0 --- End of inner exception stack trace --- at Mono.Security.X509.X509Certificate.Parse (System.Byte[] data) [0x00000] in :0 at Mono.Security.X509.X509Certificate..ctor (System.Byte[] data) [0x00000] in :0 at System.Security.Cryptography.X509Certificates.X509Certificate2.Import (System.Byte[] rawData, System.String password, X509KeyStorageFlags keyStorageFlags) [0x00000] in :0 --- End of inner exception stack trace --- at System.Security.Cryptography.X509Certificates.X509Certificate2.Import (System.Byte[] rawData, System.String password, X509KeyStorageFlags keyStorageFlags) [0x00000] in :0 at System.Security.Cryptography.X509Certificates.X509Certificate2..ctor (System.Byte[] rawData) [0x00000] in :0 --- End of relevant stack trace ---
如果重要,该认证是与我自己的CA签署的,并用于原始RSA。
我有.pfx , .cer和.pvk文件可用于此证书。
如何使用Mono下的私钥继续加载此证书?
此构造函数抛出exception:
byte[] pkcs12 = ...; X509Certificate2 cert = X509Certificate2(pkcs12);
这个构造函数工作:
byte[] pkcs12 = ...; X509Certificate2 cert = X509Certificate2(pkcs12, string.Empty);
这似乎是一个错误,所以我将修复它并向上游开发人员发送补丁。 我会告诉你进展情况。
上述就是C#学习教程:在Mono上使用X509Certificate2 – 使用公钥和私钥加载?分享的全部内容,如果对大家有所用处且需要了解更多关于C#学习教程,希望大家多多关注—计算机技术网(www.ctvol.com)!
本文来自网络收集,不代表计算机技术网立场,如涉及侵权请联系管理员删除。
ctvol管理联系方式QQ:251552304
本文章地址:https://www.ctvol.com/cdevelopment/1023254.html