diff options
author | Atsushi Eno <atsushieno@gmail.com> | 2006-09-11 19:03:53 +0400 |
---|---|---|
committer | Atsushi Eno <atsushieno@gmail.com> | 2006-09-11 19:03:53 +0400 |
commit | d268e59fdfb58e8d36f0d6ad21b64cb33930d11d (patch) | |
tree | aa6f8a469f0878f46a74f26b7221c84052910c3a /mcs/class/System/System.Security.Cryptography.X509Certificates | |
parent | 81ed9a5b7f4b89e40be700c31415ecc75e2ab8be (diff) |
2006-09-11 Atsushi Enomoto <atsushi@ximian.com>
* X509Certificate2.cs : implemented HasPrivateKey. Return null
when the corresponding RSA or DSA has no private key.
* X509Certificate2Test.cs : added test for PrivateKey and
HasPrivateKey for non-private-inclusive certificate.
svn path=/trunk/mcs/; revision=65233
Diffstat (limited to 'mcs/class/System/System.Security.Cryptography.X509Certificates')
-rw-r--r-- | mcs/class/System/System.Security.Cryptography.X509Certificates/ChangeLog | 5 | ||||
-rw-r--r-- | mcs/class/System/System.Security.Cryptography.X509Certificates/X509Certificate2.cs | 35 |
2 files changed, 33 insertions, 7 deletions
diff --git a/mcs/class/System/System.Security.Cryptography.X509Certificates/ChangeLog b/mcs/class/System/System.Security.Cryptography.X509Certificates/ChangeLog index 02eb7e69499..6e9c3f3aa61 100644 --- a/mcs/class/System/System.Security.Cryptography.X509Certificates/ChangeLog +++ b/mcs/class/System/System.Security.Cryptography.X509Certificates/ChangeLog @@ -1,3 +1,8 @@ +2006-09-11 Atsushi Enomoto <atsushi@ximian.com> + + * X509Certificate2.cs : implemented HasPrivateKey. Return null + when the corresponding RSA or DSA has no private key. + 2006-09-05 Sebastien Pouliot <sebastien@ximian.com> * X509Certificate2.cs: Call import in ctor to be sure the private key diff --git a/mcs/class/System/System.Security.Cryptography.X509Certificates/X509Certificate2.cs b/mcs/class/System/System.Security.Cryptography.X509Certificates/X509Certificate2.cs index 30b349e482d..0b55688e11a 100644 --- a/mcs/class/System/System.Security.Cryptography.X509Certificates/X509Certificate2.cs +++ b/mcs/class/System/System.Security.Cryptography.X509Certificates/X509Certificate2.cs @@ -31,7 +31,7 @@ using System.IO; using System.Text; - +using Mono.Security.Cryptography; using MX = Mono.Security.X509; namespace System.Security.Cryptography.X509Certificates { @@ -136,9 +136,9 @@ namespace System.Security.Cryptography.X509Certificates { set { _name = value; } } - [MonoTODO] + [MonoTODO ("Probably it could be more efficient")] public bool HasPrivateKey { - get { return false; } + get { return PrivateKey != null; } } [MonoTODO] @@ -160,10 +160,31 @@ namespace System.Security.Cryptography.X509Certificates { public AsymmetricAlgorithm PrivateKey { get { - if (_cert.RSA != null) - return _cert.RSA; - else if (_cert.DSA != null) - return _cert.DSA; + if (_cert.RSA != null) { + RSACryptoServiceProvider rcsp = _cert.RSA as RSACryptoServiceProvider; + if (rcsp != null) + return rcsp.PublicOnly ? null : rcsp; + RSAManaged rsam = _cert.RSA as RSAManaged; + if (rsam != null) + return rsam.PublicOnly ? null : rsam; + try { + _cert.RSA.ExportParameters (true); + return _cert.RSA; + } catch (CryptographicException) { + return null; + } + } + else if (_cert.DSA != null) { + DSACryptoServiceProvider dcsp = _cert.DSA as DSACryptoServiceProvider; + if (dcsp != null) + return dcsp.PublicOnly ? null : dcsp; + try { + _cert.DSA.ExportParameters (true); + return _cert.DSA; + } catch (CryptographicException) { + return null; + } + } return null; } set { |