Bug 16352 - new X509Certificate2() from file NotSupportedException?
Summary: new X509Certificate2() from file NotSupportedException?
Status: CONFIRMED
Alias: None
Product: Class Libraries
Classification: Mono
Component: Mono.Security ()
Version: unspecified
Hardware: PC Windows
: Low normal
Target Milestone: Untriaged
Assignee: Bugzilla
URL:
Depends on:
Blocks:
 
Reported: 2013-11-19 19:10 UTC by spyhunter73
Modified: 2018-03-02 09:36 UTC (History)
4 users (show)

Tags:
Is this bug a regression?: ---
Last known good build:

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.


Please create a new report for Bug 16352 on GitHub or Developer Community if you have new information to add and do not yet see a matching new report.

If the latest results still closely match this report, you can use the original description:

  • Export the original title and description: GitHub Markdown or Developer Community HTML
  • Copy the title and description into the new report. Adjust them to be up-to-date if needed.
  • Add your new information.

In special cases on GitHub you might also want the comments: GitHub Markdown with public comments

Related Links:
Status:
CONFIRMED

Description spyhunter73 2013-11-19 19:10:13 UTC
I'm trying to programmatically load a pfx file from c# code and ended up with this.

System.Security.Cryptography.CryptographicException : Input data cannot be coded as a valid certificate.
  ----> System.NotSupportedException : Undefined length encoding.
  at Mono.Security.X509.X509Certificate.Parse (System.Byte[] data) [0x00000] 
  at Mono.Security.X509.X509Certificate..ctor (System.Byte[] data) [0x00000] 
  at System.Security.Cryptography.X509Certificates.X509Certificate.Import (System.Byte[] rawData, System.String password, X509KeyStorageFlags keyStorageFlags) [0x00000] 
  at System.Security.Cryptography.X509Certificates.X509Certificate2.Import (System.Byte[] rawData, System.String password, X509KeyStorageFlags keyStorageFlags) [0x00000] 
  at System.Security.Cryptography.X509Certificates.X509Certificate2.Import (System.String fileName, System.String password, X509KeyStorageFlags keyStorageFlags) [0x00000] 
  at System.Security.Cryptography.X509Certificates.X509Certificate2..ctor (System.String fileName, System.String password) [0x00000]
Comment 1 Sebastien Pouliot 2014-01-22 17:09:19 UTC
The ASN.1 decoder used by Mono does not support undefined length encoding. Sadly it's not a simple fix since it would require to rework everything ASN.1-based in Mono and would break existing APIs.
Comment 2 Clovis Coli Jr 2015-05-06 18:06:14 UTC
I'm having the same problem.

var cer = new X509Certificate2(myCertificateBytes, certificatePassword);
Exception: "Input data cannot be coded as a valid certificate"

at Mono.Security.ASN1..ctor (System.Byte[] data) [0x00000] in <filename unknown>:0 \n  
at Mono.Security.X509.X509Certificate.Parse (System.Byte[] data) [0x00000] in <filename unknown>:0
in <filename unknown>:0 \n  at Mono.Security.X509.X509Certificate..ctor (System.Byte[] data) [0x00000] 
in <filename unknown>:0 \n  at System.Security.Cryptography.X509Certificates.X509Certificate2.Import (System.Byte[] rawData, System.String password, X509KeyStorageFlags keyStorageFlags) [0x00000] 
in <filename unknown>:0 \n  at System.Security.Cryptography.X509Certificates.X509Certificate2..ctor (System.Byte[] rawData, System.String password) [0x00000] 

There prediction of implementation for this problem?