Created
July 15, 2017 13:41
-
-
Save Neio/c4c87fcdfa2b148d1b377bec7d2b43cd to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class CipherHelper | |
{ | |
[DllImport("Bcrypt.dll", CharSet = CharSet.Unicode)] | |
static extern uint BCryptEnumContextFunctions(uint dwTable, string pszContext, uint dwInterface, ref uint pcbBuffer, ref IntPtr ppBuffer); | |
[DllImport("Bcrypt.dll")] | |
static extern void BCryptFreeBuffer(IntPtr pvBuffer); | |
[StructLayout(LayoutKind.Sequential)] | |
struct CRYPT_CONTEXT_FUNCTIONS | |
{ | |
public uint cFunctions; | |
public IntPtr rgpszFunctions; | |
} | |
const uint CRYPT_LOCAL = 0x00000001; | |
const uint NCRYPT_SCHANNEL_INTERFACE = 0x00010002; | |
const uint CRYPT_PRIORITY_TOP = 0x00000000; | |
const uint CRYPT_PRIORITY_BOTTOM = 0xFFFFFFFF; | |
public static IEnumerable<string> GetCipherAlgorithms() | |
{ | |
uint cbBuffer = 0; | |
IntPtr ppBuffer = IntPtr.Zero; | |
uint Status = BCryptEnumContextFunctions( | |
CRYPT_LOCAL, | |
"SSL", | |
NCRYPT_SCHANNEL_INTERFACE, | |
ref cbBuffer, | |
ref ppBuffer); | |
if (Status == 0) | |
{ | |
CRYPT_CONTEXT_FUNCTIONS functions = (CRYPT_CONTEXT_FUNCTIONS)Marshal.PtrToStructure(ppBuffer, typeof(CRYPT_CONTEXT_FUNCTIONS)); | |
try | |
{ | |
IntPtr pStr = functions.rgpszFunctions; | |
for (int i = 0; i < functions.cFunctions; i++) | |
{ | |
yield return Marshal.PtrToStringUni(Marshal.ReadIntPtr(pStr)); | |
pStr += IntPtr.Size; | |
} | |
} | |
finally | |
{ | |
BCryptFreeBuffer(ppBuffer); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment