Terraria v1.4.4.9
Terraria source code documentation
All Classes Namespaces Files Functions Variables Enumerations Enumerator Properties Events Macros
DesBCryptModes.cs
Go to the documentation of this file.
1using System;
4
6
7internal static class DesBCryptModes
8{
9 private static readonly Lazy<SafeAlgorithmHandle> s_hAlgCbc = OpenDesAlgorithm("ChainingModeCBC");
10
11 private static readonly Lazy<SafeAlgorithmHandle> s_hAlgEcb = OpenDesAlgorithm("ChainingModeECB");
12
13 private static readonly Lazy<SafeAlgorithmHandle> s_hAlgCfb8 = OpenDesAlgorithm("ChainingModeCFB");
14
15 internal static SafeAlgorithmHandle GetSharedHandle(CipherMode cipherMode, int feedback)
16 {
17 switch (cipherMode)
18 {
19 case CipherMode.CFB:
20 if (feedback != 1)
21 {
22 break;
23 }
24 return s_hAlgCfb8.Value;
25 case CipherMode.CBC:
26 return s_hAlgCbc.Value;
27 case CipherMode.ECB:
28 return s_hAlgEcb.Value;
29 }
30 throw new NotSupportedException();
31 }
32
33 private static Lazy<SafeAlgorithmHandle> OpenDesAlgorithm(string cipherMode)
34 {
35 return new Lazy<SafeAlgorithmHandle>(delegate
36 {
38 safeAlgorithmHandle.SetCipherMode(cipherMode);
39 return safeAlgorithmHandle;
40 });
41 }
42}
static readonly Lazy< SafeAlgorithmHandle > s_hAlgEcb
static SafeAlgorithmHandle GetSharedHandle(CipherMode cipherMode, int feedback)
static readonly Lazy< SafeAlgorithmHandle > s_hAlgCfb8
static readonly Lazy< SafeAlgorithmHandle > s_hAlgCbc
static Lazy< SafeAlgorithmHandle > OpenDesAlgorithm(string cipherMode)
static SafeAlgorithmHandle BCryptOpenAlgorithmProvider(string pszAlgId, string pszImplementation, OpenAlgorithmProviderFlags dwFlags)
Definition Cng.cs:34