Windows Dev Center

Information
The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.

CertificateRequestProperties.CertificateRequestProperties constructor

Creates and initializes a new instance of the CertificateRequestProperties.

Syntax


var certificateRequestProperties = new Windows.Security.Cryptography.Certificates.CertificateRequestProperties();

Parameters

This constructor has no parameters.

Remarks

This method sets the following default values.

PropertyDefault value

Subject

Empty string

KeyAlgorithmName

RSA

KeySize

2048 bits

FriendlyName

Empty String

HashAlgorithmName

SHA256

Exportable

Not Exportable

KeyUsages

Signing

KeyProtectionLevel

NoConsent

KeyStorageProviderName

Microsoft Software Key Storage Provider

 

Examples


using Windows.Security.Cryptography.Certificates;
using System.Threading.Tasks;

namespace SampleCertificateRequestProperties
{

    sealed partial class CertificateRequestPropertiesApp : Application
    {
        public CertificateRequestPropertiesApp()
        {
            // Initialize the application
            this.InitializeComponent();

            // Set and retrieve the export option.
            ExportOption exportable = this.GetSetExportable(ExportOption.Exportable);

            // Set and retrieve the display name.
            String strDisplayName = this.GetSetDisplayName("NewDisplayName");

            // Set and retrieve the hashing algorithm name.
            String strHashAlgName = this.GetSetHashAlgorithm(HashAlgorithmNames.Sha512);

            // Set and retrieve the public key algorithm name.
            String strPublicKeyAlgName = this.GetSetPublicKeyAlgorithm(KeyAlgorithmNames.Ecdsa384);

            // Set and retrieve the key protection level.
            KeyProtectionLevel level = this.GetSetKeyProtectionLevel(KeyProtectionLevel.ConsentWithPassword);

            // Set and retrieve the size, in bits, of the private key.
            UInt32 keySize = this.GetSetKeySize(4096);

            // Set and retrieve the name of the key storage provider.
            String strKspName = this.GetSetKspName(KeyStorageProviderNames.PlatformKeyStorageProvider);

            // Set and retrieve the key usage.
            EnrollKeyUsages keyUse = this.GetSetKeyUsage(EnrollKeyUsages.Decryption);

            // Set and retrieve the certificate subject name.
            String strSubject = this.GetSetSubjectName("NewSubjectName");
        }

        public ExportOption GetSetExportable(ExportOption inputOption)
        {
            // Create a new CertificateRequestProperties object.
            CertificateRequestProperties reqProperties = new CertificateRequestProperties();
            
            // The default value is ExportOption.NotExportable
            ExportOption defaultOption = reqProperties.Exportable;

            // If the input option does not equal the default option, reset the property value.
            if (inputOption != defaultOption)
            {
                reqProperties.Exportable = inputOption;
            }

            // Return the option value.
            return reqProperties.Exportable;
        }

        public String GetSetDisplayName(String strDisplayNameIn)
        {
            // Create a new CertificateRequestProperties object.
            CertificateRequestProperties reqProperties = new CertificateRequestProperties();
            
            // The default value is an empty string.
            String defaultName = reqProperties.FriendlyName;

            // If the input option does not equal the default option, reset the property value.
            if (strDisplayNameIn != defaultName)
            {
                reqProperties.FriendlyName = strDisplayNameIn;
            }

            // Return the display name.
            return reqProperties.FriendlyName;

        }

        public String GetSetHashAlgorithm(String strAlgNameIn)
        {
            // Create a new CertificateRequestProperties object.
            CertificateRequestProperties reqProperties = new CertificateRequestProperties();

            // The default value is SHA256.
            String strDefaultAlgName = reqProperties.HashAlgorithmName;

            // If the input option does not equal the default option, reset the property value.
            if (strAlgNameIn != strDefaultAlgName)
            {
                reqProperties.HashAlgorithmName = strAlgNameIn;
            }

            // Return the algorithm name.
            return reqProperties.HashAlgorithmName;
        }

        public String GetSetPublicKeyAlgorithm(String strAlgNameIn)
        {
            // Create a new CertificateRequestProperties object.
            CertificateRequestProperties reqProperties = new CertificateRequestProperties();

            // The default value is RSA.
            String strDefaultAlgName = reqProperties.KeyAlgorithmName;

            // If the input option does not equal the default option, reset the property value.
            if (strAlgNameIn != strDefaultAlgName)
            {
                reqProperties.KeyAlgorithmName = strAlgNameIn;
            }

            // Return the algorithm name.
            return reqProperties.KeyAlgorithmName;
        }

        public KeyProtectionLevel GetSetKeyProtectionLevel(KeyProtectionLevel levelIn)
        {
            // Create a new CertificateRequestProperties object.
            CertificateRequestProperties reqProperties = new CertificateRequestProperties();

            // The default value is NoConsent.
            KeyProtectionLevel defaultLevel = reqProperties.KeyProtectionLevel;

            // If the input option does not equal the default option, reset the property value.
            if (levelIn != defaultLevel)
            {
                reqProperties.KeyProtectionLevel = levelIn;
            }

            // return the key protection level.
            return reqProperties.KeyProtectionLevel;
        }

        public UInt32 GetSetKeySize(UInt32 sizeIn)
        {
            // Create a new CertificateRequestProperties object.
            CertificateRequestProperties reqProperties = new CertificateRequestProperties();

            // The default value is 2048 bits.
            UInt32 uDefaultSize = reqProperties.KeySize;

            // If the input option does not equal the default option, reset the property value.
            if (SizeIn != uDefaultSize)
            {
                reqProperties.KeySize = SizeIn;
            }

            // Return the key size.
            return reqProperties.KeySize;
        }

        public String GetSetKspName(String strNameIn)
        {
            // Create a new CertificateRequestProperties object.
            CertificateRequestProperties reqProperties = new CertificateRequestProperties();

            // The default value is Microsoft Software Key Storage Provider.
            String strDefaultName = reqProperties.KeyStorageProviderName;

            // If the input option does not equal the default option, reset the property value.
            if (strNameIn != strDefaultName)
            {
                reqProperties.KeyStorageProviderName = strNameIn;
            }

            // Return the KSP name.
            return reqProperties.KeyStorageProviderName;
        }

        public EnrollKeyUsages GetSetKeyUsage(EnrollKeyUsages keyUseIn)
        {
            // Create a new CertificateRequestProperties object.
            CertificateRequestProperties reqProperties = new CertificateRequestProperties();

            // The default value is signing.
            EnrollKeyUsages defaultKeyUse = reqProperties.KeyUsages;

            // If the input option does not equal the default option, reset the property value.
            if (keyUseIn != defaultKeyUse)
            {
                reqProperties.KeyUsages = keyUseIn;
            }

            // Return the value.
            return reqProperties.KeyUsages;
        }

        public String GetSetSubjectName(String strNameIn)
        {
            // Create a new CertificateRequestProperties object.
            CertificateRequestProperties reqProperties = new CertificateRequestProperties();

            // The default value is an empty string.
            String strDefaultName = reqProperties.Subject;

            // If the input option does not equal the default option, reset the property value.
            if (strNameIn != strDefaultName)
            {
                reqProperties.Subject = strNameIn;
            }

            // Return the subject name.
            return reqProperties.Subject;
        }
    }
}


Requirements (device family)

Device family

Universal

API contract

Windows.Foundation.UniversalApiContract, introduced version 1.0

Namespace

Windows.Security.Cryptography.Certificates
Windows::Security::Cryptography::Certificates [C++]

Metadata

Windows.Foundation.UniversalApiContract.winmd

Requirements (operating system)

Minimum supported client

Windows 8

Minimum supported server

Windows Server 2012

Minimum supported phone

Windows Phone 8.1 [Windows Runtime apps only]

Namespace

Windows.Security.Cryptography.Certificates
Windows::Security::Cryptography::Certificates [C++]

Metadata

Windows.winmd

See also

CertificateRequestProperties

 

 

Show:
© 2015 Microsoft