Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
RSACertificateExtensions.cs
Go to the documentation of this file.
3
5
6public static class RSACertificateExtensions
7{
8 public static RSA? GetRSAPublicKey(this X509Certificate2 certificate)
9 {
10 return certificate.GetPublicKey<RSA>();
11 }
12
13 public static RSA? GetRSAPrivateKey(this X509Certificate2 certificate)
14 {
15 return certificate.GetPrivateKey<RSA>();
16 }
17
18 public static X509Certificate2 CopyWithPrivateKey(this X509Certificate2 certificate, RSA privateKey)
19 {
20 if (certificate == null)
21 {
22 throw new ArgumentNullException("certificate");
23 }
24 if (privateKey == null)
25 {
26 throw new ArgumentNullException("privateKey");
27 }
28 if (certificate.HasPrivateKey)
29 {
31 }
32 using (RSA rSA = certificate.GetRSAPublicKey())
33 {
34 if (rSA == null)
35 {
37 }
38 RSAParameters rSAParameters = rSA.ExportParameters(includePrivateParameters: false);
39 RSAParameters rSAParameters2 = privateKey.ExportParameters(includePrivateParameters: false);
40 if (!rSAParameters.Modulus.ContentsEqual(rSAParameters2.Modulus) || !rSAParameters.Exponent.ContentsEqual(rSAParameters2.Exponent))
41 {
43 }
44 }
45 ICertificatePal pal = certificate.Pal.CopyWithPrivateKey(privateKey);
46 return new X509Certificate2(pal);
47 }
48}
static string Cryptography_Cert_AlreadyHasPrivateKey
Definition SR.cs:40
static string Cryptography_PrivateKey_WrongAlgorithm
Definition SR.cs:86
static string Cryptography_PrivateKey_DoesNotMatch
Definition SR.cs:84
Definition SR.cs:7
RSAParameters ExportParameters(bool includePrivateParameters)
static X509Certificate2 CopyWithPrivateKey(this X509Certificate2 certificate, RSA privateKey)
ICertificatePal CopyWithPrivateKey(DSA privateKey)