Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
TripleDES.cs
Go to the documentation of this file.
4
6
7[UnsupportedOSPlatform("browser")]
8public abstract class TripleDES : SymmetricAlgorithm
9{
10 private static readonly KeySizes[] s_legalBlockSizes = new KeySizes[1]
11 {
12 new KeySizes(64, 64, 0)
13 };
14
15 private static readonly KeySizes[] s_legalKeySizes = new KeySizes[1]
16 {
17 new KeySizes(128, 192, 64)
18 };
19
20 public override byte[] Key
21 {
22 get
23 {
24 byte[] key = base.Key;
25 while (IsWeakKey(key))
26 {
28 key = base.Key;
29 }
30 return key;
31 }
32 set
33 {
34 if (value == null)
35 {
36 throw new ArgumentNullException("value");
37 }
38 if (!(value.Length * 8).IsLegalSize(s_legalKeySizes))
39 {
41 }
42 if (IsWeakKey(value))
43 {
45 }
46 base.Key = value;
47 }
48 }
49
50 protected TripleDES()
51 {
52 KeySizeValue = 192;
53 BlockSizeValue = 64;
55 LegalBlockSizesValue = s_legalBlockSizes.CloneKeySizesArray();
56 LegalKeySizesValue = s_legalKeySizes.CloneKeySizesArray();
57 }
58
59 public new static TripleDES Create()
60 {
61 return new TripleDesImplementation();
62 }
63
64 [RequiresUnreferencedCode("The default algorithm implementations might be removed, use strong type references like 'RSA.Create()' instead.")]
65 public new static TripleDES? Create(string str)
66 {
68 }
69
70 public static bool IsWeakKey(byte[] rgbKey)
71 {
72 if (rgbKey == null)
73 {
75 }
76 if (!(rgbKey.Length * 8).IsLegalSize(s_legalKeySizes))
77 {
79 }
80 byte[] array = rgbKey.FixupKeyParity();
81 if (EqualBytes(array, 0, 8, 8))
82 {
83 return true;
84 }
85 if (array.Length == 24 && EqualBytes(array, 8, 16, 8))
86 {
87 return true;
88 }
89 return false;
90 }
91
92 private static bool EqualBytes(byte[] rgbKey, int start1, int start2, int count)
93 {
94 for (int i = 0; i < count; i++)
95 {
96 if (rgbKey[start1 + i] != rgbKey[start2 + i])
97 {
98 return false;
99 }
100 }
101 return true;
102 }
103}
static string Format(string resourceFormat, object p1)
Definition SR.cs:118
static string Cryptography_InvalidKey_Weak
Definition SR.cs:96
static string Cryptography_InvalidKeySize
Definition SR.cs:92
Definition SR.cs:7
static ? object CreateFromName(string name, params object?[]? args)
static new? TripleDES Create(string str)
Definition TripleDES.cs:65
static bool IsWeakKey(byte[] rgbKey)
Definition TripleDES.cs:70
static readonly KeySizes[] s_legalKeySizes
Definition TripleDES.cs:15
static readonly KeySizes[] s_legalBlockSizes
Definition TripleDES.cs:10
static bool EqualBytes(byte[] rgbKey, int start1, int start2, int count)
Definition TripleDES.cs:92
static new TripleDES Create()
Definition TripleDES.cs:59