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

◆ CopyWithPersistedCngKey()

unsafe ICertificatePal Internal.Cryptography.Pal.CertificatePal.CopyWithPersistedCngKey ( CngKey cngKey)
inlineprivate

Definition at line 860 of file CertificatePal.cs.

861 {
862 //The blocks IL_0090, IL_00a9, IL_00ac, IL_00ae, IL_00ce are reachable both inside and outside the pinned region starting at IL_008b. ILSpy has duplicated these blocks in order to place them both within and outside the `fixed` statement.
863 if (string.IsNullOrEmpty(cngKey.KeyName))
864 {
865 return null;
866 }
868 CngProvider provider = cngKey.Provider;
869 string keyName = cngKey.KeyName;
870 bool isMachineKey = cngKey.IsMachineKey;
871 int dwKeySpec = GuessKeySpec(provider, keyName, isMachineKey, cngKey.AlgorithmGroup);
873 fixed (char* pwszContainerName = cngKey.KeyName)
874 {
875 string provider2 = cngKey.Provider.Provider;
876 char* intPtr;
878 int dwFlags;
879 if (provider2 == null)
880 {
881 char* pwszProvName;
882 intPtr = (pwszProvName = null);
883 cRYPT_KEY_PROV_INFO.pwszContainerName = pwszContainerName;
884 cRYPT_KEY_PROV_INFO.pwszProvName = pwszProvName;
886 dwFlags = (isMachineKey ? 32 : 0);
887 reference.dwFlags = (CryptAcquireContextFlags)dwFlags;
888 cRYPT_KEY_PROV_INFO.dwKeySpec = dwKeySpec;
889 if (!global::Interop.crypt32.CertSetCertificateContextProperty(certificatePal._certContext, CertContextPropId.CERT_KEY_PROV_INFO_PROP_ID, CertSetPropertyFlags.None, &cRYPT_KEY_PROV_INFO))
890 {
891 certificatePal.Dispose();
892 throw Marshal.GetLastWin32Error().ToCryptographicException();
893 }
894 }
895 else
896 {
897 fixed (char* ptr = &provider2.GetPinnableReference())
898 {
899 char* pwszProvName;
900 intPtr = (pwszProvName = ptr);
901 cRYPT_KEY_PROV_INFO.pwszContainerName = pwszContainerName;
902 cRYPT_KEY_PROV_INFO.pwszProvName = pwszProvName;
904 dwFlags = (int)(reference.dwFlags = (isMachineKey ? CryptAcquireContextFlags.CRYPT_MACHINE_KEYSET : CryptAcquireContextFlags.None));
905 cRYPT_KEY_PROV_INFO.dwKeySpec = dwKeySpec;
906 if (!global::Interop.crypt32.CertSetCertificateContextProperty(certificatePal._certContext, CertContextPropId.CERT_KEY_PROV_INFO_PROP_ID, CertSetPropertyFlags.None, &cRYPT_KEY_PROV_INFO))
907 {
908 certificatePal.Dispose();
909 throw Marshal.GetLastWin32Error().ToCryptographicException();
910 }
911 }
912 }
913 }
914 return certificatePal;
915 }
static int GuessKeySpec(CngProvider provider, string keyName, bool machineKey, CngAlgorithmGroup algorithmGroup)
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(), Internal.Cryptography.Pal.CertificatePal.GuessKeySpec(), Microsoft.Win32.SafeHandles.SafePasswordHandle.InvalidHandle, and Internal.Cryptography.Pal.CertificatePal.RawData.

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