public static bool Exists(string keyName, CngProvider provider, CngKeyOpenOptions options) { ArgumentNullException.ThrowIfNull(keyName); ArgumentNullException.ThrowIfNull(provider); using (SafeNCryptProviderHandle providerHandle = provider.OpenStorageProvider()) { SafeNCryptKeyHandle?keyHandle = null; try { ErrorCode errorCode = Interop.NCrypt.NCryptOpenKey(providerHandle, out keyHandle, keyName, 0, options); if (errorCode == ErrorCode.NTE_BAD_KEYSET) { return(false); } if (errorCode != ErrorCode.ERROR_SUCCESS) { throw errorCode.ToCryptographicException(); } return(true); } finally { if (keyHandle != null) { keyHandle.Dispose(); } } } }
public static CngKey Open(string keyName, CngProvider provider, CngKeyOpenOptions openOptions) { if (keyName == null) { throw new ArgumentNullException("keyName"); } if (provider == null) { throw new ArgumentNullException("provider"); } if (!NCryptNative.NCryptSupported) { throw new PlatformNotSupportedException(System.SR.GetString("Cryptography_PlatformNotSupported")); } KeyContainerPermissionAccessEntry accessEntry = new KeyContainerPermissionAccessEntry(keyName, KeyContainerPermissionFlags.Open) { ProviderName = provider.Provider }; KeyContainerPermission permission = new KeyContainerPermission(KeyContainerPermissionFlags.NoFlags); permission.AccessEntries.Add(accessEntry); permission.Demand(); SafeNCryptProviderHandle kspHandle = NCryptNative.OpenStorageProvider(provider.Provider); return(new CngKey(kspHandle, NCryptNative.OpenKey(kspHandle, keyName, openOptions))); }
public static bool Exists(string keyName, CngProvider provider, CngKeyOpenOptions options) { bool flag2; if (keyName == null) { throw new ArgumentNullException("keyName"); } if (provider == null) { throw new ArgumentNullException("provider"); } if (!NCryptNative.NCryptSupported) { throw new PlatformNotSupportedException(System.SR.GetString("Cryptography_PlatformNotSupported")); } using (SafeNCryptProviderHandle handle = NCryptNative.OpenStorageProvider(provider.Provider)) { using (SafeNCryptKeyHandle handle2 = null) { NCryptNative.ErrorCode code = NCryptNative.UnsafeNativeMethods.NCryptOpenKey(handle, out handle2, keyName, 0, options); bool flag = (code == NCryptNative.ErrorCode.KeyDoesNotExist) || (code == NCryptNative.ErrorCode.NotFound); if ((code != NCryptNative.ErrorCode.Success) && !flag) { throw new CryptographicException((int)code); } flag2 = code == NCryptNative.ErrorCode.Success; } } return(flag2); }
public static bool Exists(string keyName, CngProvider provider, CngKeyOpenOptions options) { if (keyName == null) throw new ArgumentNullException(nameof(keyName)); if (provider == null) throw new ArgumentNullException(nameof(provider)); using (SafeNCryptProviderHandle providerHandle = provider.OpenStorageProvider()) { SafeNCryptKeyHandle keyHandle = null; try { ErrorCode errorCode = Interop.NCrypt.NCryptOpenKey(providerHandle, out keyHandle, keyName, 0, options); if (errorCode == ErrorCode.NTE_BAD_KEYSET) return false; if (errorCode != ErrorCode.ERROR_SUCCESS) throw errorCode.ToCryptographicException(); return true; } finally { if (keyHandle != null) keyHandle.Dispose(); } } }
/// <summary> /// Constructs the core to use a stored CNG key. /// </summary> public CngSymmetricAlgorithmCore(string algorithm, ICngSymmetricAlgorithm outer, string keyName, CngProvider provider, CngKeyOpenOptions openOptions) { if (keyName == null) { throw new ArgumentNullException("keyName"); } if (provider == null) { throw new ArgumentNullException("provider"); } _algorithm = algorithm; _outer = outer; _keyName = keyName; _provider = provider; _optionOptions = openOptions; using (CngKey cngKey = ProduceCngKey()) { CngAlgorithm actualAlgorithm = cngKey.Algorithm; if (algorithm != actualAlgorithm.Algorithm) { throw new CryptographicException(SR.GetString(SR.Cryptography_CngKeyWrongAlgorithm, actualAlgorithm.Algorithm, algorithm)); } _outer.BaseKeySize = cngKey.KeySize; } }
/// <summary> /// Constructs the core to use a stored CNG key. /// </summary> public CngSymmetricAlgorithmCore(ICngSymmetricAlgorithm outer, string keyName, CngProvider provider, CngKeyOpenOptions openOptions) { if (keyName == null) { throw new ArgumentNullException(nameof(keyName)); } if (provider == null) { throw new ArgumentNullException(nameof(provider)); } _outer = outer; _keyName = keyName; _provider = provider; _optionOptions = openOptions; using (CngKey cngKey = ProduceCngKey()) { CngAlgorithm actualAlgorithm = cngKey.Algorithm; string algorithm = _outer.GetNCryptAlgorithmIdentifier(); if (algorithm != actualAlgorithm.Algorithm) { throw new CryptographicException(SR.Format(SR.Cryptography_CngKeyWrongAlgorithm, actualAlgorithm.Algorithm, algorithm)); } _outer.BaseKeySize = cngKey.KeySize; } }
public static CngKey Open(string keyName, CngProvider provider, CngKeyOpenOptions openOptions) { Contract.Ensures(Contract.Result <CngKey>() != null); if (keyName == null) { throw new ArgumentNullException("keyName"); } if (provider == null) { throw new ArgumentNullException("provider"); } // Make sure that NCrypt is supported on this platform if (!NCryptNative.NCryptSupported) { throw new PlatformNotSupportedException(SR.GetString(SR.Cryptography_PlatformNotSupported)); } // Ensure the user has access to the key name KeyContainerPermissionAccessEntry access = new KeyContainerPermissionAccessEntry(keyName, KeyContainerPermissionFlags.Open); access.ProviderName = provider.Provider; KeyContainerPermission permission = new KeyContainerPermission(KeyContainerPermissionFlags.NoFlags); permission.AccessEntries.Add(access); permission.Demand(); // Open the key SafeNCryptProviderHandle kspHandle = NCryptNative.OpenStorageProvider(provider.Provider); SafeNCryptKeyHandle keyHandle = NCryptNative.OpenKey(kspHandle, keyName, openOptions); return(new CngKey(kspHandle, keyHandle)); }
/// <summary> /// Given a KeyProvider and a KeyName, decrypts the data with the given key /// </summary> /// <param name="providerName">Provider where the key is stored</param> /// <param name="keyName">Name of the key to use</param> /// <param name="toDecrypt">Data to decrypt</param> /// <param name="hashAlgorithm">OAEP hash algorithm, Look in PaddingHashAlgorithmNames.cs for values, but supports only SHA1, SHA256, SHA384, SHA512</param> /// <param name="paddingFlags">Padding Type, Look in PaddingFlags.cs for values, but supports only PKCS1 amd OAEP</param> /// <exception cref="CryptographicException">Cryptographic Exception</exception> /// <returns>The decrypted data</returns> public byte[] DecryptWithLocalKey(string providerName, string keyName, byte[] toDecrypt, string hashAlgorithm = PaddingHashAlgorithmNames.SHA512, int paddingFlags = PaddingFlags.OAEPPadding) { CngProvider provider = new CngProvider(providerName); byte[] decrypted; CngKeyOpenOptions cngkeyOpenOpts = CngKeyOpenOptions.MachineKey; bool keyExists = doesKeyExists(provider, keyName, cngkeyOpenOpts); if (!keyExists) { if (doesKeyExists(provider, keyName, CngKeyOpenOptions.None)) { cngkeyOpenOpts = CngKeyOpenOptions.None; } else { throw new CryptographicException(string.Format("They key {0} does not exist and cannot be used for decryption", keyName)); } } using (CngKey key = CngKey.Open(keyName, provider, cngkeyOpenOpts)) { using (RSACng rsa = new RSACng(key)) { RSAEncryptionPadding padding = this.GetRSAPadding(hashAlgorithm, paddingFlags); decrypted = rsa.Decrypt(toDecrypt, padding); } } return(decrypted); }
/// <summary> /// Configures the core to use plaintext keys (to be auto-generated when first needed.) /// </summary> public CngSymmetricAlgorithmCore(ICngSymmetricAlgorithm outer) { _outer = outer; _keyName = null; // Setting _keyName to null signifies that this object is based on a plaintext key, not a stored CNG key. _provider = null; _optionOptions = CngKeyOpenOptions.None; }
public static IEnumerable<CngKey> GetKeys(this CngProvider provider, CngKeyOpenOptions openOptions) { using (SafeNCryptProviderHandle providerHandle = provider.OpenProvider()) { foreach (var key in NCryptNative.EnumerateKeys(providerHandle, openOptions)) { yield return CngKey.Open(key.pszName, provider); } } }
public static IEnumerable <CngKey> GetKeys(this CngProvider provider, CngKeyOpenOptions openOptions) { using (SafeNCryptProviderHandle providerHandle = provider.OpenProvider()) { foreach (var key in NCryptNative.EnumerateKeys(providerHandle, openOptions)) { yield return(CngKey.Open(key.pszName, provider)); } } }
public FindOptions() { _keyOpenOptions = CngKeyOpenOptions.MachineKey | CngKeyOpenOptions.UserKey; _opts = new OptionSet() { { "n|name=", "The name of the key to find", v => Name = v }, { "un=|unique-name=", "A partial match for the key's unique name", v => UniqueId = v } }; Provider = CngProvider.MicrosoftSoftwareKeyStorageProvider; }
public FindOptions() { _keyOpenOptions = CngKeyOpenOptions.MachineKey | CngKeyOpenOptions.UserKey; _opts = new OptionSet() { {"n|name=", "The name of the key to find", v => Name = v}, {"un=|unique-name=", "A partial match for the key's unique name", v => UniqueId = v} }; Provider = CngProvider.MicrosoftSoftwareKeyStorageProvider; }
/// <summary> /// Get all of the keys for a specific algorithm supported by the provider /// </summary> public static IEnumerable<CngKey> GetKeys(this CngProvider provider, CngKeyOpenOptions openOptions, CngAlgorithm algorithm) { if (algorithm == null) throw new ArgumentNullException("algorithm"); return from key in provider.GetKeys(openOptions) where key.Algorithm == algorithm select key; }
private static int GuessKeySpec( CngProvider provider, string keyName, bool machineKey, CngAlgorithmGroup algorithmGroup) { if (provider == CngProvider.MicrosoftSoftwareKeyStorageProvider || provider == CngProvider.MicrosoftSmartCardKeyStorageProvider) { // Well-known CNG providers, keySpec is 0. return(0); } const int NTE_BAD_KEYSET = unchecked ((int)0x80090016); try { CngKeyOpenOptions options = machineKey ? CngKeyOpenOptions.MachineKey : CngKeyOpenOptions.None; using (CngKey.Open(keyName, provider, options)) { // It opened with keySpec 0, so use keySpec 0. return(0); } } catch (CryptographicException e) { Debug.Assert( e.HResult == NTE_BAD_KEYSET, $"CngKey.Open had unexpected error: 0x{e.HResult:X8}: {e.Message}"); CspParameters cspParameters = new CspParameters { ProviderName = provider.Provider, KeyContainerName = keyName, Flags = CspProviderFlags.UseExistingKey, KeyNumber = (int)KeyNumber.Signature, }; if (machineKey) { cspParameters.Flags |= CspProviderFlags.UseMachineKeyStore; } int keySpec; if (TryGuessKeySpec(cspParameters, algorithmGroup, out keySpec)) { return(keySpec); } throw; } }
private static int GuessKeySpec( CngProvider provider, string keyName, bool machineKey, CngAlgorithmGroup?algorithmGroup) { if (provider == CngProvider.MicrosoftSoftwareKeyStorageProvider || provider == CngProvider.MicrosoftSmartCardKeyStorageProvider) { // Well-known CNG providers, keySpec is 0. return(0); } try { CngKeyOpenOptions options = machineKey ? CngKeyOpenOptions.MachineKey : CngKeyOpenOptions.None; using (CngKey.Open(keyName, provider, options)) { // It opened with keySpec 0, so use keySpec 0. return(0); } } catch (CryptographicException) { // While NTE_BAD_KEYSET is what we generally expect here for RSA, on Windows 7 // PROV_DSS produces NTE_BAD_PROV_TYPE, and PROV_DSS_DH produces NTE_NO_KEY. // // So we'll just try the CAPI fallback for any error code, and see what happens. CspParameters cspParameters = new CspParameters { ProviderName = provider.Provider, KeyContainerName = keyName, Flags = CspProviderFlags.UseExistingKey, KeyNumber = (int)KeyNumber.Signature, }; if (machineKey) { cspParameters.Flags |= CspProviderFlags.UseMachineKeyStore; } int keySpec; if (TryGuessKeySpec(cspParameters, algorithmGroup, out keySpec)) { return(keySpec); } throw; } }
/// <summary> /// GetKeys provides an enumerator over all of the keys that are stored in the key storage /// provider. This overload of GetKeys allows you to enumerate over only the user keys in the KSP /// or only the machine keys. It also allows you to return only keys that are usable with a /// specified algorithm. /// </summary> /// <param name="provider">CngProvider to enumerate the keys of</param> /// <param name="openOptions">options to use when opening the CNG keys</param> /// <param name="algorithm">algorithm that the returned keys should support</param> /// <exception cref="ArgumentNullException">if <paramref name="algorithm" /> is null</exception> public static IEnumerable <CngKey> GetKeys(this CngProvider provider, CngKeyOpenOptions openOptions, CngAlgorithm algorithm) { if (algorithm == null) { throw new ArgumentNullException("algorithm"); } return(from key in provider.GetKeys(openOptions) where key.Algorithm == algorithm select key); }
private static int GuessKeySpec(CngProvider provider, string keyName, bool machineKey, CngAlgorithmGroup algorithmGroup) { if (provider == CngProvider.MicrosoftSoftwareKeyStorageProvider || provider == CngProvider.MicrosoftSmartCardKeyStorageProvider) { return(0); } CngKeyOpenOptions openOptions = machineKey ? CngKeyOpenOptions.MachineKey : CngKeyOpenOptions.None; using (CngKey.Open(keyName, provider, openOptions)) { return(0); } }
internal static NCryptKeyName[] EnumerateKeys(SafeNCryptProviderHandle provider, CngKeyOpenOptions openOptions) { Debug.Assert(provider != null && !provider.IsClosed && !provider.IsInvalid, "Invalid provider"); IntPtr enumState = IntPtr.Zero; SafeNCryptBuffer algorithmBuffer = null; RuntimeHelpers.PrepareConstrainedRegions(); try { List <NCryptKeyName> keys = new List <NCryptKeyName>(); ErrorCode enumStatus = ErrorCode.Success; // Loop over the NCryptEnumKeys until it tells us that there are no more keys to enumerate do { enumStatus = UnsafeNativeMethods.NCryptEnumKeys(provider, null, out algorithmBuffer, ref enumState, openOptions); if (enumStatus == ErrorCode.Success) { keys.Add(algorithmBuffer.ReadArray <NCryptKeyName>(0)); } else if (enumStatus != ErrorCode.NoMoreItems) { throw new CryptographicException((int)enumStatus); } }while (enumStatus == ErrorCode.Success); return(keys.ToArray()); } finally { if (enumState != IntPtr.Zero) { UnsafeNativeMethods.NCryptFreeBuffer(enumState); } if (algorithmBuffer != null) { algorithmBuffer.Dispose(); } } }
public static CngKey Open(string keyName, CngProvider provider, CngKeyOpenOptions openOptions) { if (keyName == null) throw new ArgumentNullException("keyName"); if (provider == null) throw new ArgumentNullException("provider"); SafeNCryptProviderHandle providerHandle = provider.OpenStorageProvider(); SafeNCryptKeyHandle keyHandle; ErrorCode errorCode = Interop.NCrypt.NCryptOpenKey(providerHandle, out keyHandle, keyName, 0, openOptions); if (errorCode != ErrorCode.ERROR_SUCCESS) throw errorCode.ToCryptographicException(); return new CngKey(providerHandle, keyHandle); }
public static IEnumerable <CngKey> GetKeys(this CngProvider provider, CngKeyOpenOptions openOptions) { using (SafeNCryptProviderHandle providerHandle = provider.OpenProvider()) { NCryptNative.NCryptKeyName[] keyNames = NCryptNative.EnumerateKeys(providerHandle, openOptions); CngKey[] keys = new CngKey[keyNames.Length]; for (int i = 0; i < keys.Length; ++i) { keys[i] = CngKey.Open(keyNames[i].pszName, provider); } return(keys); } }
/// <summary> /// Check for the existence of a key and set the Options accordingly. /// </summary> /// <param name="provider">Provider Object</param> /// <param name="keyName">Name of the key to destroy</param> /// <param name="cngKeyOpts">MachineKey or None depending on where it found the key.</param> /// <returns></returns> private bool doesKeyExists(CngProvider provider, string keyName, CngKeyOpenOptions openOpts = CngKeyOpenOptions.MachineKey) { bool keyExists = false; try { keyExists = CngKey.Exists(keyName, provider, openOpts); } catch (CryptographicException e) { throw new CryptographicException(string.Format("There was an error contacting provider {0}. It may not exist or may be configured incorrectly. Error Code:0x{1:X8} Exception thrown:{2}\nStack Trace:{3}\n", provider.ToString(), e.HResult, e.Message, e.StackTrace), e); } return(keyExists); }
public static CngKey Open(string keyName, CngProvider provider, CngKeyOpenOptions openOptions) { ArgumentNullException.ThrowIfNull(keyName); ArgumentNullException.ThrowIfNull(provider); SafeNCryptProviderHandle providerHandle = provider.OpenStorageProvider(); SafeNCryptKeyHandle keyHandle; ErrorCode errorCode = Interop.NCrypt.NCryptOpenKey(providerHandle, out keyHandle, keyName, 0, openOptions); if (errorCode != ErrorCode.ERROR_SUCCESS) { throw errorCode.ToCryptographicException(); } return(new CngKey(providerHandle, keyHandle)); }
public static bool Exists(string keyName, CngProvider provider, CngKeyOpenOptions options) { if (keyName == null) { throw new ArgumentNullException("keyName"); } if (provider == null) { throw new ArgumentNullException("provider"); } // Make sure that NCrypt is supported on this platform if (!NCryptNative.NCryptSupported) { throw new PlatformNotSupportedException(SR.GetString(SR.Cryptography_PlatformNotSupported)); } using (SafeNCryptProviderHandle kspHandle = NCryptNative.OpenStorageProvider(provider.Provider)) { SafeNCryptKeyHandle keyHandle = null; try { NCryptNative.ErrorCode error = NCryptNative.UnsafeNativeMethods.NCryptOpenKey(kspHandle, out keyHandle, keyName, 0, options); // CNG will return either NTE_NOT_FOUND or NTE_BAD_KEYSET for the case where the key does // not exist, so we need to check for both return codes. bool keyNotFound = error == NCryptNative.ErrorCode.KeyDoesNotExist || error == NCryptNative.ErrorCode.NotFound; if (error != NCryptNative.ErrorCode.Success && !keyNotFound) { throw new CryptographicException((int)error); } return(error == NCryptNative.ErrorCode.Success); } finally { if (keyHandle != null) { keyHandle.Dispose(); } } } }
/// <summary> /// Constructs the core to use a stored CNG key. /// </summary> public CngSymmetricAlgorithmCore(string algorithm, ICngSymmetricAlgorithm outer, string keyName, CngProvider provider, CngKeyOpenOptions openOptions) { if (keyName == null) throw new ArgumentNullException("keyName"); if (provider == null) throw new ArgumentNullException("provider"); _algorithm = algorithm; _outer = outer; _keyName = keyName; _provider = provider; _optionOptions = openOptions; using (CngKey cngKey = ProduceCngKey()) { CngAlgorithm actualAlgorithm = cngKey.Algorithm; if (algorithm != actualAlgorithm.Algorithm) throw new CryptographicException(SR.Format(SR.Cryptography_CngKeyWrongAlgorithm, actualAlgorithm.Algorithm, algorithm)); _outer.BaseKeySize = cngKey.KeySize; } }
public AesCng(string keyName, CngProvider provider, CngKeyOpenOptions openOptions) { _core = new CngSymmetricAlgorithmCore(this, keyName, provider, openOptions); }
public static CngKey Open(string keyName, CngProvider provider, CngKeyOpenOptions openOptions) { if (keyName == null) { throw new ArgumentNullException("keyName"); } if (provider == null) { throw new ArgumentNullException("provider"); } if (!NCryptNative.NCryptSupported) { throw new PlatformNotSupportedException(System.SR.GetString("Cryptography_PlatformNotSupported")); } KeyContainerPermissionAccessEntry accessEntry = new KeyContainerPermissionAccessEntry(keyName, KeyContainerPermissionFlags.Open) { ProviderName = provider.Provider }; KeyContainerPermission permission = new KeyContainerPermission(KeyContainerPermissionFlags.NoFlags); permission.AccessEntries.Add(accessEntry); permission.Demand(); SafeNCryptProviderHandle kspHandle = NCryptNative.OpenStorageProvider(provider.Provider); return new CngKey(kspHandle, NCryptNative.OpenKey(kspHandle, keyName, openOptions)); }
public TripleDESCng (string keyName, CngProvider provider, CngKeyOpenOptions openOptions) { throw new NotImplementedException (); }
public static CngKey Open(string keyName, CngProvider provider, CngKeyOpenOptions openOptions) { throw new NotImplementedException(); }
public static bool Exists(string keyName, CngProvider provider, CngKeyOpenOptions options) { if (keyName == null) { throw new ArgumentNullException("keyName"); } if (provider == null) { throw new ArgumentNullException("provider"); } // Make sure that NCrypt is supported on this platform if (!NCryptNative.NCryptSupported) { throw new PlatformNotSupportedException(SR.GetString(SR.Cryptography_PlatformNotSupported)); } using (SafeNCryptProviderHandle kspHandle = NCryptNative.OpenStorageProvider(provider.Provider)) { SafeNCryptKeyHandle keyHandle = null; try { NCryptNative.ErrorCode error = NCryptNative.UnsafeNativeMethods.NCryptOpenKey(kspHandle, out keyHandle, keyName, 0, options); // CNG will return either NTE_NOT_FOUND or NTE_BAD_KEYSET for the case where the key does // not exist, so we need to check for both return codes. bool keyNotFound = error == NCryptNative.ErrorCode.KeyDoesNotExist || error == NCryptNative.ErrorCode.NotFound; if (error != NCryptNative.ErrorCode.Success && !keyNotFound) { throw new CryptographicException((int)error); } return error == NCryptNative.ErrorCode.Success; } finally { if (keyHandle != null) { keyHandle.Dispose(); } } } }
public TripleDESCng(string keyName, CngProvider provider, CngKeyOpenOptions openOptions) { _core = new CngSymmetricAlgorithmCore(this, keyName, provider, openOptions); }
internal static extern int NCryptGetProperty(SafeNCryptHandle hObject, string pszProperty, [Out, MarshalAs(UnmanagedType.LPArray)] byte[] pbOutput, int cbOutput, [Out] out int pcbResult, CngKeyOpenOptions dwFlags);
internal static extern ErrorCode NCryptEnumKeys(SafeNCryptProviderHandle hProvider, [In, MarshalAs(UnmanagedType.LPWStr)] string pszScope, [Out] out SafeNCryptBuffer ppKeyName, [In, Out] ref IntPtr ppEnumState, CngKeyOpenOptions dwFlags);
internal static SafeNCryptKeyHandle OpenKey(SafeNCryptProviderHandle provider, string name, CngKeyOpenOptions options) { SafeNCryptKeyHandle phKey = null; ErrorCode code = UnsafeNativeMethods.NCryptOpenKey(provider, out phKey, name, 0, options); if (code != ErrorCode.Success) { throw new CryptographicException((int)code); } return(phKey); }
public static CngKey Open(string keyName, CngProvider provider, CngKeyOpenOptions openOptions) { Contract.Ensures(Contract.Result <System.Security.Cryptography.CngKey>() != null); return(default(CngKey)); }
internal static extern ErrorCode NCryptOpenKey(SafeNCryptProviderHandle hProvider, out SafeNCryptKeyHandle phKey, string pszKeyName, int dwLegacyKeySpec, CngKeyOpenOptions dwFlags);
public static CngKey Open(string keyName, CngProvider provider, CngKeyOpenOptions openOptions) { Contract.Ensures(Contract.Result<CngKey>() != null); if (keyName == null) { throw new ArgumentNullException("keyName"); } if (provider == null) { throw new ArgumentNullException("provider"); } // Make sure that NCrypt is supported on this platform if (!NCryptNative.NCryptSupported) { throw new PlatformNotSupportedException(SR.GetString(SR.Cryptography_PlatformNotSupported)); } // Ensure the user has access to the key name KeyContainerPermissionAccessEntry access = new KeyContainerPermissionAccessEntry(keyName, KeyContainerPermissionFlags.Open); access.ProviderName = provider.Provider; KeyContainerPermission permission = new KeyContainerPermission(KeyContainerPermissionFlags.NoFlags); permission.AccessEntries.Add(access); permission.Demand(); // Open the key SafeNCryptProviderHandle kspHandle = NCryptNative.OpenStorageProvider(provider.Provider); SafeNCryptKeyHandle keyHandle = NCryptNative.OpenKey(kspHandle, keyName, openOptions); return new CngKey(kspHandle, keyHandle); }
private static extern SECURITY_STATUS NCryptOpenKey( SafeNCryptProviderHandle hProvider, [Out] out SafeNCryptKeyHandle phKey, string pszKeyName, int dwLegacyKeySpec, CngKeyOpenOptions dwFlags);
public TripleDESCng(string keyName, CngProvider provider, CngKeyOpenOptions openOptions) { throw new NotImplementedException(); }
public static CngKey Open(string keyName, CngProvider provider, CngKeyOpenOptions openOptions) { Contract.Ensures(Contract.Result<System.Security.Cryptography.CngKey>() != null); return default(CngKey); }
public AesCng(string keyName, CngProvider provider, CngKeyOpenOptions openOptions) { throw new PlatformNotSupportedException(SR.PlatformNotSupported_CryptographyCng); }
public static bool Exists(string keyName, CngProvider provider, CngKeyOpenOptions options) { return default(bool); }
public static bool Exists(string keyName, CngProvider provider, CngKeyOpenOptions options) { bool flag2; if (keyName == null) { throw new ArgumentNullException("keyName"); } if (provider == null) { throw new ArgumentNullException("provider"); } if (!NCryptNative.NCryptSupported) { throw new PlatformNotSupportedException(System.SR.GetString("Cryptography_PlatformNotSupported")); } using (SafeNCryptProviderHandle handle = NCryptNative.OpenStorageProvider(provider.Provider)) { using (SafeNCryptKeyHandle handle2 = null) { NCryptNative.ErrorCode code = NCryptNative.UnsafeNativeMethods.NCryptOpenKey(handle, out handle2, keyName, 0, options); bool flag = (code == NCryptNative.ErrorCode.KeyDoesNotExist) || (code == NCryptNative.ErrorCode.NotFound); if ((code != NCryptNative.ErrorCode.Success) && !flag) { throw new CryptographicException((int) code); } flag2 = code == NCryptNative.ErrorCode.Success; } } return flag2; }
public static bool Exists(string keyName, CngProvider provider, CngKeyOpenOptions options) { return(default(bool)); }
public static CngKey Open(string keyName, CngProvider provider, CngKeyOpenOptions openOptions) { throw new NotImplementedException (); }
internal static extern int NCryptGetProperty(SafeNCryptHandle hObject, string pszProperty, [Out] out IntPtr pbOutput, int cbOutput, [Out] out int pcbResult, CngKeyOpenOptions dwFlags);