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

◆ FromBlobOrFile()

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

Definition at line 457 of file CertificatePal.cs.

458 {
459 bool flag = fileName != null;
461 bool deleteKeyContainer = false;
465 try
466 {
468 fixed (byte* pbData = rawData)
469 {
470 fixed (char* ptr = fileName)
471 {
472 CRYPTOAPI_BLOB cRYPTOAPI_BLOB = new CRYPTOAPI_BLOB((!flag) ? rawData.Length : 0, pbData);
473 CertQueryObjectType dwObjectType = (flag ? CertQueryObjectType.CERT_QUERY_OBJECT_FILE : CertQueryObjectType.CERT_QUERY_OBJECT_BLOB);
474 void* pvObject = (flag ? ((void*)ptr) : ((void*)(&cRYPTOAPI_BLOB)));
475 if (!global::Interop.crypt32.CryptQueryObject(dwObjectType, pvObject, ExpectedContentTypeFlags.CERT_QUERY_CONTENT_FLAG_CERT | ExpectedContentTypeFlags.CERT_QUERY_CONTENT_FLAG_SERIALIZED_CERT | ExpectedContentTypeFlags.CERT_QUERY_CONTENT_FLAG_PKCS7_SIGNED | ExpectedContentTypeFlags.CERT_QUERY_CONTENT_FLAG_PKCS7_SIGNED_EMBED | ExpectedContentTypeFlags.CERT_QUERY_CONTENT_FLAG_PFX, ExpectedFormatTypeFlags.CERT_QUERY_FORMAT_FLAG_ALL, 0, out var _, out pdwContentType, out var _, out phCertStore, out phMsg, out ppvContext))
476 {
478 throw hRForLastWin32Error.ToCryptographicException();
479 }
480 }
481 }
482 switch (pdwContentType)
483 {
484 case ContentType.CERT_QUERY_CONTENT_PKCS7_SIGNED:
485 case ContentType.CERT_QUERY_CONTENT_PKCS7_SIGNED_EMBED:
487 break;
488 case ContentType.CERT_QUERY_CONTENT_PFX:
489 if (flag)
490 {
492 }
494 deleteKeyContainer = (keyStorageFlags & (X509KeyStorageFlags.PersistKeySet | X509KeyStorageFlags.EphemeralKeySet)) == 0;
495 break;
496 }
498 ppvContext = null;
499 return result;
500 }
501 finally
502 {
503 phCertStore?.Dispose();
504 phMsg?.Dispose();
505 ppvContext?.Dispose();
506 }
507 }
static PfxCertStoreFlags MapKeyStorageFlags(X509KeyStorageFlags keyStorageFlags)
static unsafe SafeCertContextHandle FilterPFXStore(ReadOnlySpan< byte > rawData, SafePasswordHandle password, PfxCertStoreFlags pfxCertStoreFlags)
static unsafe SafeCertContextHandle GetSignerInPKCS7Store(SafeCertStoreHandle hCertStore, SafeCryptMsgHandle hCryptMsg)
static byte[] ReadAllBytes(string path)
Definition File.cs:314

References Internal.Cryptography.Pal.CertificatePal.CertificatePal(), Internal.Cryptography.Pal.CertificatePal.FilterPFXStore(), System.Runtime.InteropServices.Marshal.GetHRForLastWin32Error(), Internal.Cryptography.Pal.CertificatePal.GetSignerInPKCS7Store(), Internal.Cryptography.Pal.CertificatePal.MapKeyStorageFlags(), and System.IO.File.ReadAllBytes().

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