Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
SafeCertContextHandleWithKeyContainerDeletion.cs
Go to the documentation of this file.
1using System;
4
6
8{
9 protected sealed override bool ReleaseHandle()
10 {
11 using (SafeCertContextHandle pCertContext = global::Interop.crypt32.CertDuplicateCertificateContext(handle))
12 {
13 DeleteKeyContainer(pCertContext);
14 }
15 base.ReleaseHandle();
16 return true;
17 }
18
19 public unsafe static void DeleteKeyContainer(SafeCertContextHandle pCertContext)
20 {
21 if (pCertContext.IsInvalid)
22 {
23 return;
24 }
25 int pcbData = 0;
26 if (!global::Interop.crypt32.CertGetCertificateContextProperty(pCertContext, CertContextPropId.CERT_KEY_PROV_INFO_PROP_ID, null, ref pcbData))
27 {
28 return;
29 }
30 byte[] array = new byte[pcbData];
31 if (!global::Interop.crypt32.CertGetCertificateContextProperty(pCertContext, CertContextPropId.CERT_KEY_PROV_INFO_PROP_ID, array, ref pcbData))
32 {
33 return;
34 }
35 fixed (byte* ptr = array)
36 {
38 if (ptr2->dwProvType == 0)
39 {
40 string provider = Marshal.PtrToStringUni((IntPtr)ptr2->pwszProvName);
41 string keyName = Marshal.PtrToStringUni((IntPtr)ptr2->pwszContainerName);
42 try
43 {
44 using CngKey cngKey = CngKey.Open(keyName, new CngProvider(provider));
45 cngKey.Delete();
46 }
48 {
49 }
50 }
51 else
52 {
53 CryptAcquireContextFlags dwFlags = (ptr2->dwFlags & CryptAcquireContextFlags.CRYPT_MACHINE_KEYSET) | CryptAcquireContextFlags.CRYPT_DELETEKEYSET;
54 global::Interop.cryptoapi.CryptAcquireContext(out var _, ptr2->pwszContainerName, ptr2->pwszProvName, ptr2->dwProvType, dwFlags);
55 }
56 }
57 }
58}
static unsafe? string PtrToStringUni(IntPtr ptr)
Definition Marshal.cs:652
static CngKey Open(string keyName)
Definition CngKey.cs:799