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

◆ CopyWithPersistedCapiKey()

unsafe ICertificatePal Internal.Cryptography.Pal.CertificatePal.CopyWithPersistedCapiKey ( CspKeyContainerInfo keyContainerInfo)
inlineprivate

Definition at line 1012 of file CertificatePal.cs.

1013 {
1014 //The blocks IL_0063, IL_0080, IL_0083, IL_0085, IL_00b6 are reachable both inside and outside the pinned region starting at IL_005e. ILSpy has duplicated these blocks in order to place them both within and outside the `fixed` statement.
1015 if (string.IsNullOrEmpty(keyContainerInfo.KeyContainerName))
1016 {
1017 return null;
1018 }
1021 fixed (char* pwszContainerName = keyContainerInfo.KeyContainerName)
1022 {
1023 string? providerName = keyContainerInfo.ProviderName;
1024 char* intPtr;
1026 int dwFlags;
1027 if (providerName == null)
1028 {
1029 char* pwszProvName;
1030 intPtr = (pwszProvName = null);
1031 cRYPT_KEY_PROV_INFO.pwszContainerName = pwszContainerName;
1032 cRYPT_KEY_PROV_INFO.pwszProvName = pwszProvName;
1034 dwFlags = (keyContainerInfo.MachineKeyStore ? 32 : 0);
1035 reference.dwFlags = (CryptAcquireContextFlags)dwFlags;
1036 cRYPT_KEY_PROV_INFO.dwProvType = keyContainerInfo.ProviderType;
1037 cRYPT_KEY_PROV_INFO.dwKeySpec = (int)keyContainerInfo.KeyNumber;
1038 if (!global::Interop.crypt32.CertSetCertificateContextProperty(certificatePal._certContext, CertContextPropId.CERT_KEY_PROV_INFO_PROP_ID, CertSetPropertyFlags.None, &cRYPT_KEY_PROV_INFO))
1039 {
1040 certificatePal.Dispose();
1041 throw Marshal.GetLastWin32Error().ToCryptographicException();
1042 }
1043 }
1044 else
1045 {
1046 fixed (char* ptr = &providerName.GetPinnableReference())
1047 {
1048 char* pwszProvName;
1049 intPtr = (pwszProvName = ptr);
1050 cRYPT_KEY_PROV_INFO.pwszContainerName = pwszContainerName;
1051 cRYPT_KEY_PROV_INFO.pwszProvName = pwszProvName;
1053 dwFlags = (int)(reference.dwFlags = (keyContainerInfo.MachineKeyStore ? CryptAcquireContextFlags.CRYPT_MACHINE_KEYSET : CryptAcquireContextFlags.None));
1054 cRYPT_KEY_PROV_INFO.dwProvType = keyContainerInfo.ProviderType;
1055 cRYPT_KEY_PROV_INFO.dwKeySpec = (int)keyContainerInfo.KeyNumber;
1056 if (!global::Interop.crypt32.CertSetCertificateContextProperty(certificatePal._certContext, CertContextPropId.CERT_KEY_PROV_INFO_PROP_ID, CertSetPropertyFlags.None, &cRYPT_KEY_PROV_INFO))
1057 {
1058 certificatePal.Dispose();
1059 throw Marshal.GetLastWin32Error().ToCryptographicException();
1060 }
1061 }
1062 }
1063 }
1064 return certificatePal;
1065 }
static ICertificatePal FromBlob(ReadOnlySpan< byte > rawData, SafePasswordHandle password, X509KeyStorageFlags keyStorageFlags)

References Internal.Cryptography.Pal.CertificatePal.CertificatePal(), Internal.Cryptography.Pal.CertificatePal.FromBlob(), System.Runtime.InteropServices.Marshal.GetLastWin32Error(), Microsoft.Win32.SafeHandles.SafePasswordHandle.InvalidHandle, and Internal.Cryptography.Pal.CertificatePal.RawData.

Referenced by Internal.Cryptography.Pal.CertificatePal.CopyWithPrivateKey(), and Internal.Cryptography.Pal.CertificatePal.CopyWithPrivateKey().