File: System\Security\Cryptography\CspParameters.cs
Web Access
Project: src\src\libraries\System.Security.Cryptography\src\System.Security.Cryptography.csproj (System.Security.Cryptography)
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
 
using System.Diagnostics;
using System.Runtime.Versioning;
 
namespace System.Security.Cryptography
{
    [SupportedOSPlatform("windows")]
    public sealed class CspParameters
    {
        public int ProviderType;
        public string? ProviderName;
        public string? KeyContainerName;
        public int KeyNumber;
        private int _flags;
        private IntPtr _parentWindowHandle;
 
        /// <summary>
        /// Flag property
        /// </summary>
        public CspProviderFlags Flags
        {
            get
            {
                return (CspProviderFlags)_flags;
            }
            set
            {
                int allFlags = 0x00FF; // this should change if more values are added to CspProviderFlags
                Debug.Assert((CspProviderFlags.UseMachineKeyStore |
                              CspProviderFlags.UseDefaultKeyContainer |
                              CspProviderFlags.UseNonExportableKey |
                              CspProviderFlags.UseExistingKey |
                              CspProviderFlags.UseArchivableKey |
                              CspProviderFlags.UseUserProtectedKey |
                              CspProviderFlags.NoPrompt |
                              CspProviderFlags.CreateEphemeralKey) == (CspProviderFlags)allFlags, "allFlags does not match all CspProviderFlags");
 
                int flags = (int)value;
                if ((flags & ~allFlags) != 0)
                {
                    throw new ArgumentException(SR.Format(SR.Arg_EnumIllegalVal, nameof(value)));
                }
                _flags = flags;
            }
        }
 
        [CLSCompliantAttribute(false)]
        public SecureString? KeyPassword { get; set; }
 
        public CspParameters() : this(CapiHelper.DefaultRsaProviderType, null, null) { }
 
        public CspParameters(int dwTypeIn) : this(dwTypeIn, null, null) { }
        public CspParameters(int dwTypeIn, string? strProviderNameIn) : this(dwTypeIn, strProviderNameIn, null) { }
        public CspParameters(int dwTypeIn, string? strProviderNameIn, string? strContainerNameIn) :
            this(dwTypeIn, strProviderNameIn, strContainerNameIn, CspProviderFlags.NoFlags)
        {
        }
 
        internal CspParameters(int providerType, string? providerName, string? keyContainerName, CspProviderFlags flags)
        {
            ProviderType = providerType;
            ProviderName = providerName;
            KeyContainerName = keyContainerName;
            KeyNumber = -1;
            Flags = flags;
        }
 
        //Copy constructor
        internal CspParameters(CspParameters parameters)
        {
            ProviderType = parameters.ProviderType;
            ProviderName = parameters.ProviderName;
            KeyContainerName = parameters.KeyContainerName;
            KeyNumber = parameters.KeyNumber;
            KeyPassword = parameters.KeyPassword;
            Flags = parameters.Flags;
            _parentWindowHandle = parameters._parentWindowHandle;
        }
 
        public IntPtr ParentWindowHandle
        {
            get
            {
                return _parentWindowHandle;
            }
            set
            {
                _parentWindowHandle = value;
            }
        }
    }
}