new internal static SafeLocalAllocHandle LocalAlloc(uint uFlags, uint sizetdwBytes) { SafeLocalAllocHandle safeLocalAllocHandle = CAPIMethods.LocalAlloc(uFlags, sizetdwBytes); if (safeLocalAllocHandle == null || safeLocalAllocHandle.IsInvalid) { throw new OutOfMemoryException(); } return(safeLocalAllocHandle); }
new internal static bool CryptGetProvParam( SafeCryptProvHandle hProv, uint dwParam, StringBuilder pbData, ref uint dwDataLen, uint dwFlags) { bool result = CAPIMethods.CryptGetProvParam(hProv, dwParam, pbData, ref dwDataLen, dwFlags); #if DEBUG if (!result) { int errorCode = Marshal.GetLastWin32Error(); if (errorCode != 0 && errorCode != CAPI.ERROR_NO_MORE_ITEMS) { System.Diagnostics.Debug.WriteLine("Error " + errorCode); } } #endif return(result); }
internal static bool CryptAcquireContext( ref SafeCryptProvHandle hCryptProv, string pwszContainer, string pwszProvider, uint dwProvType, uint dwFlags, out int errorCode) { errorCode = 0; #if !RUNTIME_TYPE_NETCORE CspParameters parameters = new CspParameters(); parameters.ProviderName = pwszProvider; parameters.KeyContainerName = pwszContainer; parameters.ProviderType = (int)dwProvType; parameters.KeyNumber = -1; parameters.Flags = (CspProviderFlags)((dwFlags & CAPI.CRYPT_MACHINE_KEYSET) == CAPI.CRYPT_MACHINE_KEYSET ? CspProviderFlags.UseMachineKeyStore : 0); KeyContainerPermission kp = new KeyContainerPermission(KeyContainerPermissionFlags.NoFlags); KeyContainerPermissionAccessEntry entry = new KeyContainerPermissionAccessEntry(parameters, KeyContainerPermissionFlags.Open); kp.AccessEntries.Add(entry); kp.Demand(); #endif bool rc = CAPIMethods.CryptAcquireContext(ref hCryptProv, pwszContainer, pwszProvider, dwProvType, dwFlags); if (!rc) { errorCode = Marshal.GetLastWin32Error(); } return(rc); }