Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
AesBCryptModes.cs
Go to the documentation of this file.
1using System;
4
6
7internal static class AesBCryptModes
8{
9 private static readonly Lazy<SafeAlgorithmHandle> s_hAlgCbc = OpenAesAlgorithm("ChainingModeCBC");
10
11 private static readonly Lazy<SafeAlgorithmHandle> s_hAlgEcb = OpenAesAlgorithm("ChainingModeECB");
12
13 private static readonly Lazy<SafeAlgorithmHandle> s_hAlgCfb128 = OpenAesAlgorithm("ChainingModeCFB", 16);
14
15 private static readonly Lazy<SafeAlgorithmHandle> s_hAlgCfb8 = OpenAesAlgorithm("ChainingModeCFB", 1);
16
17 internal static SafeAlgorithmHandle GetSharedHandle(CipherMode cipherMode, int feedback)
18 {
19 switch (cipherMode)
20 {
21 case CipherMode.CFB:
22 switch (feedback)
23 {
24 case 16:
25 return s_hAlgCfb128.Value;
26 case 1:
27 return s_hAlgCfb8.Value;
28 }
29 break;
30 case CipherMode.CBC:
31 return s_hAlgCbc.Value;
32 case CipherMode.ECB:
33 return s_hAlgEcb.Value;
34 }
35 throw new NotSupportedException();
36 }
37
38 internal static Lazy<SafeAlgorithmHandle> OpenAesAlgorithm(string cipherMode, int feedback = 0)
39 {
40 return new Lazy<SafeAlgorithmHandle>(delegate
41 {
43 safeAlgorithmHandle.SetCipherMode(cipherMode);
44 if (feedback > 0 && feedback != 1)
45 {
46 try
47 {
48 safeAlgorithmHandle.SetFeedbackSize(feedback);
49 }
50 catch (CryptographicException inner)
51 {
53 }
54 }
55 return safeAlgorithmHandle;
56 });
57 }
58}
static Lazy< SafeAlgorithmHandle > OpenAesAlgorithm(string cipherMode, int feedback=0)
static readonly Lazy< SafeAlgorithmHandle > s_hAlgEcb
static readonly Lazy< SafeAlgorithmHandle > s_hAlgCbc
static readonly Lazy< SafeAlgorithmHandle > s_hAlgCfb8
static SafeAlgorithmHandle GetSharedHandle(CipherMode cipherMode, int feedback)
static readonly Lazy< SafeAlgorithmHandle > s_hAlgCfb128
static SafeAlgorithmHandle BCryptOpenAlgorithmProvider(string pszAlgId, string pszImplementation, OpenAlgorithmProviderFlags dwFlags)
Definition Cng.cs:34
static string Cryptography_FeedbackSizeNotSupported
Definition SR.cs:176
Definition SR.cs:7