Beispiel #1
0
 /// <summary>
 /// Creates a new private key.
 /// </summary>
 /// <param name="keyProvider">The provider for the key. <see cref="KeyProviders"/> contains different types of providers.</param>
 /// <param name="keyName">The name of the key to persist. Use <c>null</c> to create an ephemeral key.</param>
 /// <param name="algorithm">The algorithm of the key. Not all providers support all algorithms.</param>
 /// <param name="keyUsage">Specifies the purpose of the key. This is not appicable to CNG algorithms.</param>
 /// <param name="keySize">The size of the key. Only valid for RSA keys.</param>
 /// <param name="overwrite">True to overwrite the provider's exisint private key, otherwise false.</param>
 /// <returns>A new private key.</returns>
 public static PrivateKey CreateNew(KeyProviderBase keyProvider, string keyName, Algorithm algorithm, KeyUsage keyUsage, int? keySize = null, bool overwrite = false)
 {
     var keySizeValue = keySize ?? 2048;
     KeySpec keySpec;
     var handle = keyProvider.CreateKey(keyName, keySizeValue, algorithm, overwrite, keyUsage, out keySpec);
     return new PrivateKey(handle, keyProvider, keySpec);
 }
Beispiel #2
0
        /// <summary>
        /// Creates a new private key.
        /// </summary>
        /// <param name="keyProvider">The provider for the key. <see cref="KeyProviders"/> contains different types of providers.</param>
        /// <param name="keyName">The name of the key to persist. Use <c>null</c> to create an ephemeral key.</param>
        /// <param name="algorithm">The algorithm of the key. Not all providers support all algorithms.</param>
        /// <param name="keyUsage">Specifies the purpose of the key. This is not appicable to CNG algorithms.</param>
        /// <param name="keySize">The size of the key. Only valid for RSA keys.</param>
        /// <param name="overwrite">True to overwrite the provider's exisint private key, otherwise false.</param>
        /// <returns>A new private key.</returns>
        public static PrivateKey CreateNew(KeyProviderBase keyProvider, string keyName, Algorithm algorithm, KeyUsage keyUsage, int?keySize = null, bool overwrite = false)
        {
            var     keySizeValue = keySize ?? 2048;
            KeySpec keySpec;
            var     handle = keyProvider.CreateKey(keyName, keySizeValue, algorithm, overwrite, keyUsage, out keySpec);

            return(new PrivateKey(handle, keyProvider, keySpec));
        }
Beispiel #3
0
 public static PrivateKey OpenExisting(KeyProviderBase keyProvider, string keyName)
 {
     if (string.IsNullOrEmpty(keyName))
     {
         throw new ArgumentNullException(nameof(keyName));
     }
     var handle = keyProvider.OpenExisting(keyName);
     if (handle == null)
     {
         return null;
     }
     return new PrivateKey(handle, keyProvider);
 }
Beispiel #4
0
        public static PrivateKey OpenExisting(KeyProviderBase keyProvider, string keyName)
        {
            if (string.IsNullOrEmpty(keyName))
            {
                throw new ArgumentNullException(nameof(keyName));
            }
            KeySpec keySpec;
            var     handle = keyProvider.OpenExisting(keyName, out keySpec);

            if (handle == null)
            {
                return(null);
            }
            return(new PrivateKey(handle, keyProvider, keySpec));
        }
 static FiddlerCertificate()
 {
     _keyProviderEngine = PlatformSupport.HasCngSupport ? KeyProviders.CNG : KeyProviders.CAPI;
 }
Beispiel #6
0
 internal PrivateKey(NCryptKeyOrCryptProviderSafeHandle handle, KeyProviderBase keyProvider)
 {
     _handle = handle;
     _keyProvider = keyProvider;
 }
Beispiel #7
0
 internal PrivateKey(NCryptKeyOrCryptProviderSafeHandle handle, KeyProviderBase keyProvider, KeySpec keySpec)
 {
     _handle      = handle;
     _keyProvider = keyProvider;
     _keySpec     = keySpec;
 }