Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
Cng.cs
Go to the documentation of this file.
1using System;
5
7
8internal static class Cng
9{
10 [Flags]
12 {
13 NONE = 0,
15 }
16
17 internal static class Interop
18 {
19 [DllImport("BCrypt.dll", CharSet = CharSet.Unicode)]
20 public static extern global::Interop.BCrypt.NTSTATUS BCryptOpenAlgorithmProvider(out Internal.NativeCrypto.SafeAlgorithmHandle phAlgorithm, string pszAlgId, string pszImplementation, int dwFlags);
21
22 [DllImport("BCrypt.dll", CharSet = CharSet.Unicode)]
23 public static extern global::Interop.BCrypt.NTSTATUS BCryptSetProperty(Internal.NativeCrypto.SafeAlgorithmHandle hObject, string pszProperty, string pbInput, int cbInput, int dwFlags);
24
25 [DllImport("BCrypt.dll", CharSet = CharSet.Unicode, EntryPoint = "BCryptSetProperty")]
26 private static extern global::Interop.BCrypt.NTSTATUS BCryptSetIntPropertyPrivate(Microsoft.Win32.SafeHandles.SafeBCryptHandle hObject, string pszProperty, ref int pdwInput, int cbInput, int dwFlags);
27
28 public static global::Interop.BCrypt.NTSTATUS BCryptSetIntProperty(Microsoft.Win32.SafeHandles.SafeBCryptHandle hObject, string pszProperty, ref int pdwInput, int dwFlags)
29 {
30 return BCryptSetIntPropertyPrivate(hObject, pszProperty, ref pdwInput, 4, dwFlags);
31 }
32 }
33
34 public static Internal.NativeCrypto.SafeAlgorithmHandle BCryptOpenAlgorithmProvider(string pszAlgId, string pszImplementation, OpenAlgorithmProviderFlags dwFlags)
35 {
37 global::Interop.BCrypt.NTSTATUS nTSTATUS = Interop.BCryptOpenAlgorithmProvider(out phAlgorithm, pszAlgId, pszImplementation, (int)dwFlags);
38 if (nTSTATUS != 0)
39 {
40 throw CreateCryptographicException(nTSTATUS);
41 }
42 return phAlgorithm;
43 }
44
45 public static void SetFeedbackSize(this Internal.NativeCrypto.SafeAlgorithmHandle hAlg, int dwFeedbackSize)
46 {
47 global::Interop.BCrypt.NTSTATUS nTSTATUS = Interop.BCryptSetIntProperty(hAlg, "MessageBlockLength", ref dwFeedbackSize, 0);
48 if (nTSTATUS != 0)
49 {
50 throw CreateCryptographicException(nTSTATUS);
51 }
52 }
53
54 public static void SetCipherMode(this Internal.NativeCrypto.SafeAlgorithmHandle hAlg, string cipherMode)
55 {
56 global::Interop.BCrypt.NTSTATUS nTSTATUS = Interop.BCryptSetProperty(hAlg, "ChainingMode", cipherMode, (cipherMode.Length + 1) * 2, 0);
57 if (nTSTATUS != 0)
58 {
59 throw CreateCryptographicException(nTSTATUS);
60 }
61 }
62
63 private static Exception CreateCryptographicException(global::Interop.BCrypt.NTSTATUS ntStatus)
64 {
65 int hr = (int)(ntStatus | (global::Interop.BCrypt.NTSTATUS)16777216u);
66 return hr.ToCryptographicException();
67 }
68}
static global::Interop.BCrypt.NTSTATUS BCryptSetProperty(Internal.NativeCrypto.SafeAlgorithmHandle hObject, string pszProperty, string pbInput, int cbInput, int dwFlags)
static global::Interop.BCrypt.NTSTATUS BCryptSetIntPropertyPrivate(SafeBCryptHandle hObject, string pszProperty, ref int pdwInput, int cbInput, int dwFlags)
static global::Interop.BCrypt.NTSTATUS BCryptSetIntPropertyPrivate(Microsoft.Win32.SafeHandles.SafeBCryptHandle hObject, string pszProperty, ref int pdwInput, int cbInput, int dwFlags)
static global::Interop.BCrypt.NTSTATUS BCryptSetIntProperty(Microsoft.Win32.SafeHandles.SafeBCryptHandle hObject, string pszProperty, ref int pdwInput, int dwFlags)
Definition Cng.cs:28
static global::Interop.BCrypt.NTSTATUS BCryptOpenAlgorithmProvider(out SafeAlgorithmHandle phAlgorithm, string pszAlgId, string pszImplementation, int dwFlags)
static global::Interop.BCrypt.NTSTATUS BCryptSetIntProperty(SafeBCryptHandle hObject, string pszProperty, ref int pdwInput, int dwFlags)
Definition Cng.cs:28
static global::Interop.BCrypt.NTSTATUS BCryptOpenAlgorithmProvider(out Internal.NativeCrypto.SafeAlgorithmHandle phAlgorithm, string pszAlgId, string pszImplementation, int dwFlags)
static global::Interop.BCrypt.NTSTATUS BCryptSetProperty(SafeAlgorithmHandle hObject, string pszProperty, string pbInput, int cbInput, int dwFlags)
static Exception CreateCryptographicException(global::Interop.BCrypt.NTSTATUS ntStatus)
Definition Cng.cs:72
static void SetFeedbackSize(this Internal.NativeCrypto.SafeAlgorithmHandle hAlg, int dwFeedbackSize)
Definition Cng.cs:45
static void SetCipherMode(this Internal.NativeCrypto.SafeAlgorithmHandle hAlg, string cipherMode)
Definition Cng.cs:54
static Internal.NativeCrypto.SafeAlgorithmHandle BCryptOpenAlgorithmProvider(string pszAlgId, string pszImplementation, OpenAlgorithmProviderFlags dwFlags)
Definition Cng.cs:34