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

◆ FromBlobOrFile()

static unsafe StorePal Internal.Cryptography.Pal.StorePal.FromBlobOrFile ( ReadOnlySpan< byte > rawData,
string fileName,
SafePasswordHandle password,
X509KeyStorageFlags keyStorageFlags )
inlinestaticprivate

Definition at line 205 of file StorePal.cs.

206 {
207 bool flag = fileName != null;
208 fixed (byte* pbData = rawData)
209 {
210 fixed (char* ptr = fileName)
211 {
212 CRYPTOAPI_BLOB cRYPTOAPI_BLOB = new CRYPTOAPI_BLOB((!flag) ? rawData.Length : 0, pbData);
213 bool flag2 = (keyStorageFlags & X509KeyStorageFlags.PersistKeySet) != 0;
214 PfxCertStoreFlags dwFlags = MapKeyStorageFlags(keyStorageFlags);
215 void* pvObject = (flag ? ((void*)ptr) : ((void*)(&cRYPTOAPI_BLOB)));
217 {
218 throw Marshal.GetLastWin32Error().ToCryptographicException();
219 }
220 if (pdwContentType == ContentType.CERT_QUERY_CONTENT_PFX)
221 {
222 phCertStore.Dispose();
223 if (flag)
224 {
225 rawData = File.ReadAllBytes(fileName);
226 }
227 fixed (byte* pbData2 = rawData)
228 {
229 CRYPTOAPI_BLOB pPFX = new CRYPTOAPI_BLOB(rawData.Length, pbData2);
230 phCertStore = global::Interop.crypt32.PFXImportCertStore(ref pPFX, password, dwFlags);
231 if (phCertStore == null || phCertStore.IsInvalid)
232 {
233 throw Marshal.GetLastWin32Error().ToCryptographicException();
234 }
235 }
236 if (!flag2)
237 {
238 SafeCertContextHandle pCertContext = null;
239 while (global::Interop.crypt32.CertEnumCertificatesInStore(phCertStore, ref pCertContext))
240 {
241 CRYPTOAPI_BLOB cRYPTOAPI_BLOB2 = new CRYPTOAPI_BLOB(0, null);
242 if (!global::Interop.crypt32.CertSetCertificateContextProperty(pCertContext, CertContextPropId.CERT_CLR_DELETE_KEY_PROP_ID, CertSetPropertyFlags.CERT_SET_PROPERTY_INHIBIT_PERSIST_FLAG, &cRYPTOAPI_BLOB2))
243 {
244 throw Marshal.GetLastWin32Error().ToCryptographicException();
245 }
246 }
247 }
248 }
249 return new StorePal(phCertStore);
250 }
251 }
252 }
StorePal(SafeCertStoreHandle certStore)
Definition StorePal.cs:89
static PfxCertStoreFlags MapKeyStorageFlags(X509KeyStorageFlags keyStorageFlags)
Definition StorePal.cs:299
static byte[] ReadAllBytes(string path)
Definition File.cs:314

References Internal.Cryptography.Pal.StorePal.StorePal(), System.Runtime.InteropServices.Marshal.GetLastWin32Error(), System.ReadOnlySpan< T >.Length, Internal.Cryptography.Pal.StorePal.MapKeyStorageFlags(), System.IO.File.ReadAllBytes(), and System.IntPtr.Zero.

Referenced by Internal.Cryptography.Pal.StorePal.FromBlob(), and Internal.Cryptography.Pal.StorePal.FromFile().