Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches

◆ GetPrivateKey< T >()

static T Internal.Cryptography.Pal.CertificateExtensionsCommon.GetPrivateKey< T > ( this X509Certificate2 certificate,
Predicate< X509Certificate2 > matchesConstraints = null )
inlinestatic
Type Constraints
T :AsymmetricAlgorithm 

Definition at line 43 of file CertificateExtensionsCommon.cs.

44 {
45 if (certificate == null)
46 {
47 throw new ArgumentNullException("certificate");
48 }
49 string expectedOidValue = GetExpectedOidValue<T>();
50 if (!certificate.HasPrivateKey || expectedOidValue != certificate.PublicKey.Oid.Value)
51 {
52 return null;
53 }
54 if (matchesConstraints != null && !matchesConstraints(certificate))
55 {
56 return null;
57 }
58 if (typeof(T) == typeof(RSA))
59 {
60 return (T)(AsymmetricAlgorithm)certificate.Pal.GetRSAPrivateKey();
61 }
62 if (typeof(T) == typeof(ECDsa))
63 {
64 return (T)(AsymmetricAlgorithm)certificate.Pal.GetECDsaPrivateKey();
65 }
66 if (typeof(T) == typeof(DSA))
67 {
68 return (T)(AsymmetricAlgorithm)certificate.Pal.GetDSAPrivateKey();
69 }
70 if (typeof(T) == typeof(ECDiffieHellman))
71 {
72 return (T)(AsymmetricAlgorithm)certificate.Pal.GetECDiffieHellmanPrivateKey();
73 }
75 }
static string NotSupported_KeyAlgorithm
Definition SR.cs:114
Definition SR.cs:7

References Internal.Cryptography.Pal.CertificateExtensionsCommon.GetExpectedOidValue< T >(), System.Security.Cryptography.X509Certificates.X509Certificate2.HasPrivateKey, System.SR.NotSupported_KeyAlgorithm, System.Security.Cryptography.X509Certificates.PublicKey.Oid, System.Security.Cryptography.X509Certificates.X509Certificate2.Pal, System.Security.Cryptography.X509Certificates.X509Certificate2.PublicKey, and System.Security.Cryptography.Oid.Value.