Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
X509SubjectKeyIdentifierExtension.cs
Go to the documentation of this file.
3
5
7{
8 private string _subjectKeyIdentifier;
9
10 private bool _decoded;
11
12 public string? SubjectKeyIdentifier
13 {
14 get
15 {
16 if (!_decoded)
17 {
18 X509Pal.Instance.DecodeX509SubjectKeyIdentifierExtension(base.RawData, out var subjectKeyIdentifier);
19 _subjectKeyIdentifier = subjectKeyIdentifier.ToHexStringUpper();
20 _decoded = true;
21 }
23 }
24 }
25
27 : base(System.Security.Cryptography.Oids.SubjectKeyIdentifierOid)
28 {
30 _decoded = true;
31 }
32
33 public X509SubjectKeyIdentifierExtension(AsnEncodedData encodedSubjectKeyIdentifier, bool critical)
34 : base(System.Security.Cryptography.Oids.SubjectKeyIdentifierOid, encodedSubjectKeyIdentifier.RawData, critical)
35 {
36 }
37
38 public X509SubjectKeyIdentifierExtension(byte[] subjectKeyIdentifier, bool critical)
39 : this(subjectKeyIdentifier.AsSpanParameter("subjectKeyIdentifier"), critical)
40 {
41 }
42
43 public X509SubjectKeyIdentifierExtension(ReadOnlySpan<byte> subjectKeyIdentifier, bool critical)
44 : base(System.Security.Cryptography.Oids.SubjectKeyIdentifierOid, EncodeExtension(subjectKeyIdentifier), critical)
45 {
46 }
47
50 {
51 }
52
54 : base(System.Security.Cryptography.Oids.SubjectKeyIdentifierOid, EncodeExtension(key, algorithm), critical)
55 {
56 }
57
58 public X509SubjectKeyIdentifierExtension(string subjectKeyIdentifier, bool critical)
59 : base(System.Security.Cryptography.Oids.SubjectKeyIdentifierOid, EncodeExtension(subjectKeyIdentifier), critical)
60 {
61 }
62
63 public override void CopyFrom(AsnEncodedData asnEncodedData)
64 {
65 base.CopyFrom(asnEncodedData);
66 _decoded = false;
67 }
68
69 private static byte[] EncodeExtension(ReadOnlySpan<byte> subjectKeyIdentifier)
70 {
71 if (subjectKeyIdentifier.Length == 0)
72 {
73 throw new ArgumentException(System.SR.Arg_EmptyOrNullArray, "subjectKeyIdentifier");
74 }
75 return X509Pal.Instance.EncodeX509SubjectKeyIdentifierExtension(subjectKeyIdentifier);
76 }
77
78 private static byte[] EncodeExtension(string subjectKeyIdentifier)
79 {
80 if (subjectKeyIdentifier == null)
81 {
82 throw new ArgumentNullException("subjectKeyIdentifier");
83 }
84 byte[] array = subjectKeyIdentifier.DecodeHexString();
85 return EncodeExtension(array);
86 }
87
89 {
90 if (key == null)
91 {
92 throw new ArgumentNullException("key");
93 }
95 return EncodeExtension(array);
96 }
97
99 {
100 switch (algorithm)
101 {
103 return SHA1.HashData(key.EncodedKeyValue.RawData);
105 {
106 byte[] array = SHA1.HashData(key.EncodedKeyValue.RawData);
107 byte[] array2 = new byte[8];
108 Buffer.BlockCopy(array, array.Length - 8, array2, 0, array2.Length);
109 array2[0] &= 15;
110 array2[0] |= 64;
111 return array2;
112 }
114 return X509Pal.Instance.ComputeCapiSha1OfPublicKey(key);
115 default:
116 throw new ArgumentException(System.SR.Format(System.SR.Arg_EnumIllegalVal, algorithm), "algorithm");
117 }
118 }
119}
static void BlockCopy(Array src, int srcOffset, Array dst, int dstOffset, int count)
Definition Buffer.cs:102
static string Arg_EnumIllegalVal
Definition SR.cs:144
static string Format(string resourceFormat, object p1)
Definition SR.cs:118
static string Arg_EmptyOrNullArray
Definition SR.cs:14
Definition SR.cs:7
static byte[] HashData(byte[] source)
Definition SHA1.cs:66
X509SubjectKeyIdentifierExtension(ReadOnlySpan< byte > subjectKeyIdentifier, bool critical)
static byte[] EncodeExtension(PublicKey key, X509SubjectKeyIdentifierHashAlgorithm algorithm)
X509SubjectKeyIdentifierExtension(AsnEncodedData encodedSubjectKeyIdentifier, bool critical)
static byte[] GenerateSubjectKeyIdentifierFromPublicKey(PublicKey key, X509SubjectKeyIdentifierHashAlgorithm algorithm)
X509SubjectKeyIdentifierExtension(PublicKey key, X509SubjectKeyIdentifierHashAlgorithm algorithm, bool critical)