Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches

◆ Export()

unsafe byte[] Internal.Cryptography.Pal.StorePal.Export ( X509ContentType contentType,
SafePasswordHandle password )
inline

Implements Internal.Cryptography.Pal.IExportPal.

Definition at line 100 of file StorePal.cs.

101 {
102 switch (contentType)
103 {
104 case X509ContentType.Cert:
105 {
106 SafeCertContextHandle pCertContext = null;
107 if (!global::Interop.crypt32.CertEnumCertificatesInStore(_certStore, ref pCertContext))
108 {
109 return null;
110 }
111 try
112 {
113 byte[] array2 = new byte[pCertContext.CertContext->cbCertEncoded];
114 Marshal.Copy((IntPtr)pCertContext.CertContext->pbCertEncoded, array2, 0, array2.Length);
115 GC.KeepAlive(pCertContext);
116 return array2;
117 }
118 finally
119 {
120 pCertContext.Dispose();
121 }
122 }
123 case X509ContentType.SerializedCert:
124 {
125 SafeCertContextHandle pCertContext2 = null;
126 if (!global::Interop.crypt32.CertEnumCertificatesInStore(_certStore, ref pCertContext2))
127 {
128 return null;
129 }
130 try
131 {
132 int pcbElement = 0;
133 if (!global::Interop.crypt32.CertSerializeCertificateStoreElement(pCertContext2, 0, null, ref pcbElement))
134 {
135 throw Marshal.GetHRForLastWin32Error().ToCryptographicException();
136 }
137 byte[] array3 = new byte[pcbElement];
138 if (!global::Interop.crypt32.CertSerializeCertificateStoreElement(pCertContext2, 0, array3, ref pcbElement))
139 {
140 throw Marshal.GetHRForLastWin32Error().ToCryptographicException();
141 }
142 return array3;
143 }
144 finally
145 {
146 pCertContext2.Dispose();
147 }
148 }
149 case X509ContentType.Pfx:
150 {
151 CRYPTOAPI_BLOB pPFX = new CRYPTOAPI_BLOB(0, null);
152 if (!global::Interop.crypt32.PFXExportCertStore(_certStore, ref pPFX, password, PFXExportFlags.REPORT_NOT_ABLE_TO_EXPORT_PRIVATE_KEY | PFXExportFlags.EXPORT_PRIVATE_KEYS))
153 {
154 throw Marshal.GetHRForLastWin32Error().ToCryptographicException();
155 }
156 byte[] array = new byte[pPFX.cbData];
157 fixed (byte* pbData = array)
158 {
159 pPFX.pbData = pbData;
160 if (!global::Interop.crypt32.PFXExportCertStore(_certStore, ref pPFX, password, PFXExportFlags.REPORT_NOT_ABLE_TO_EXPORT_PRIVATE_KEY | PFXExportFlags.EXPORT_PRIVATE_KEYS))
161 {
162 throw Marshal.GetHRForLastWin32Error().ToCryptographicException();
163 }
164 }
165 return array;
166 }
167 case X509ContentType.SerializedStore:
168 return SaveToMemoryStore(CertStoreSaveAs.CERT_STORE_SAVE_AS_STORE);
169 case X509ContentType.Pkcs7:
170 return SaveToMemoryStore(CertStoreSaveAs.CERT_STORE_SAVE_AS_PKCS7);
171 default:
173 }
174 }
unsafe byte[] SaveToMemoryStore(CertStoreSaveAs dwSaveAs)
Definition StorePal.cs:176
SafeCertStoreHandle _certStore
Definition StorePal.cs:13
static void KeepAlive(object? obj)
Definition GC.cs:180
Definition GC.cs:8
static void Copy(int[] source, int startIndex, IntPtr destination, int length)
Definition Marshal.cs:800
static string Cryptography_X509_InvalidContentType
Definition SR.cs:94
Definition SR.cs:7

References Internal.Cryptography.Pal.StorePal._certStore, System.array, Internal.Cryptography.Pal.Native.CERT_CONTEXT.cbCertEncoded, Internal.Cryptography.Pal.Native.CRYPTOAPI_BLOB.cbData, Internal.Cryptography.Pal.Native.SafeCertContextHandle.CertContext, System.Runtime.InteropServices.Marshal.Copy(), System.SR.Cryptography_X509_InvalidContentType, Internal.Cryptography.Pal.Native.SafePointerHandle< T >.Dispose(), System.Runtime.InteropServices.Marshal.GetHRForLastWin32Error(), System.GC.KeepAlive(), Internal.Cryptography.Pal.Native.CERT_CONTEXT.pbCertEncoded, and Internal.Cryptography.Pal.StorePal.SaveToMemoryStore().