@@ -90,28 +90,37 @@ public static PublicKeyAlgorithm GetPublicKeyAlgorithm (this X509Certificate2 ce
9090 switch ( identifier ) {
9191 case "1.2.840.113549.1.1.1" : // RSA Encryption (rsaEncryption) and RSA General
9292 return PublicKeyAlgorithm . RsaGeneral ;
93+ #if false
94+ // Note: For RSA S/MIME keys, the only public‑key OID used in X.509 (and therefore S/MIME) is 1.2.840.113549.1.1.1.
9395 case "1.2.840.113549.1.1.5" : // RSA with SHA-1 (RSA Sign-Only)
9496 case "1.2.840.113549.1.1.11" : // RSA with SHA-256
9597 case "1.2.840.113549.1.1.12" : // RSA with SHA-384
9698 case "1.2.840.113549.1.1.13" : // RSA with SHA-512
9799 return PublicKeyAlgorithm . RsaSign ;
100+ #endif
98101 case "1.2.840.10040.4.1" : // DSA
99- case "1.2.840.10040.4.3" : // DSA with SHA-1
102+ // case "1.2.840.10040.4.3": // DSA with SHA-1
100103 return PublicKeyAlgorithm . Dsa ;
101104 case "1.2.840.10045.2.1" : // EC Public Key (technically also ECDSA)
102105 return PublicKeyAlgorithm . EllipticCurve ;
106+ #if false
107+ // Note: For ECDSA S/MIME keys, the only public‑key OID used in X.509 (and therefore S/MIME) is 1.2.840.10045.2.1.
108+ // The following OIDs are for ECDSA signatures, so they are not technically public-key OIDs.
103109 case "1.2.840.10045.4.1" : // ECDSA with SHA-1
104110 case "1.2.840.10045.4.3.2" : // ECDSA with SHA-256
105111 case "1.2.840.10045.4.3.3" : // ECDSA with SHA-384
106112 case "1.2.840.10045.4.3.4" : // ECDSA with SHA-512
107113 return PublicKeyAlgorithm . EllipticCurveDsa ;
114+ // Diffie-Hellman is only for key-exchange, so this is very unlikely to be the PublicKey type for an X509Certificate2.
108115 case "1.2.840.10046.2.1" : // Diffie-Hellman
109116 return PublicKeyAlgorithm . DiffieHellman ;
117+ // EdDSA is not yet supported by .NET, so this is very unlikely to be the PublicKey type for an X509Certificate2.
110118 case "1.3.101.110" : // X25519 (Curve25519 for ECDH)
111119 case "1.3.101.111" : // X448 (Curve448 for ECDH)
112120 case "1.3.101.112" : // Ed25519 (EdDSA signature)
113121 case "1.3.101.113" : // Ed448 (EdDSA signature)
114122 return PublicKeyAlgorithm . EdwardsCurveDsa ;
123+ #endif
115124 default :
116125 return PublicKeyAlgorithm . None ;
117126 }
@@ -260,30 +269,20 @@ public static EncryptionAlgorithm[] GetEncryptionAlgorithms (this X509Certificat
260269 AsymmetricKeyParameter ? key = null ;
261270
262271 switch ( GetPublicKeyAlgorithm ( certificate ) ) {
263- case PublicKeyAlgorithm . RsaEncrypt :
264272 case PublicKeyAlgorithm . RsaGeneral :
265- case PublicKeyAlgorithm . RsaSign :
266273 privateKey = certificate . GetRSAPrivateKey ( ) ;
267274 break ;
268275 case PublicKeyAlgorithm . Dsa :
269276 privateKey = certificate . GetDSAPrivateKey ( ) ;
270277 break ;
271278 case PublicKeyAlgorithm . EllipticCurve :
272- case PublicKeyAlgorithm . EllipticCurveDsa :
273279 privateKey = certificate . GetECDsaPrivateKey ( ) ;
274280 break ;
275- case PublicKeyAlgorithm . DiffieHellman :
276- // Note: I think this is only a key-exchange algorithm, so this should be very unlikely?
277- privateKey = certificate . GetECDiffieHellmanPrivateKey ( ) ;
278- break ;
279281 }
280282
281283 if ( privateKey != null ) {
282- try {
284+ using ( privateKey )
283285 key = privateKey . AsAsymmetricKeyParameter ( ) ;
284- } finally {
285- privateKey . Dispose ( ) ;
286- }
287286 }
288287
289288 return key ;
0 commit comments