Language: HTML | XAML

Creating a certificate request Windows Runtime app using JavaScript

Applies to Windows and Windows Phone

To create a certificate request, you must first create a CertificateRequestProperties object and define the properties your certificate should have. By default, the constructor sets the following properties.

PropertyDefault value

Subject

Empty string

KeyAlgorithmName

KeyAlgorithmNames.RSA

KeySize

KeySize.RSA2048

FriendlyName

Empty String

HashAlgorithmName

HashAlgorithmNames.Sha256

Exportable

ExportOption.NotExportable

KeyUsages

EnrollKeyUsage.Signing

KeyProtectionLevel

KeyProtectionLevel.NoConsent

KeyStorageProviderName

KeystorageProviderNames.SoftwareKeyStorageProvider

This is the "Microsoft Software Key Storage Provider"

 

To create the request, call the CreateRequestAsync method. This is shown by the following example.



function createCertificateRequest() {

    // Declare a certificate request message.
    var myMessage = "";

    // Note - The default constructor for a CertificateRequestProperties object
    // sets the following default property values:
    //
    //      subject: "" -- empty string
    //      keyAlgorithm: KeyAlgorithm.RSA
    //      keySize: KeySizes.RSA2048  -- 2048 bits
    //      friendlyName: "" -- empty string
    //      hashAlgorithm: HashAlgorithms.SHA256
    //      exportable: ExportOptions.NotExportable
    //      keyUsage: EnrollKeyUsages.Signing 
    //      keyProtectionLevel: KeyProtectionLevel.NoConsent
    //      keyStorageProvider: KeystorageProviders.SoftwareKsp -- "Microsoft Software Key Storage Provider"

    try {

        // Create a default CertificateRequestProperties object.
        var myRequestProperties = new Windows.Security.Cryptography.Certificates.CertificateRequestProperties();

        // Override the default subject and display names.
        myRequestProperties.subject = "Toby";
        myRequestProperties.friendlyName = "Toby's Cert";

        // Call a custom function to convert the request properties to a string.
        myMessage = "Create certificate request:" + convertCertificateRequestPropertiestoString(myRequestProperties);

        // Create a certificate request from the CertificateRequestProperties object.
        myRequest = Windows.Security.Cryptography.Certificates.CertificateEnrollmentManager.createRequest(myRequestProperties);
        myMessage = myMessage + "\n\nCertificate request creation succeeded.\nEncoded request String:\n " + myRequest;

        // Display the request string in your program (here called SDKSample)
        sdkSample.displayStatus(myMessage);
    }
    catch (e) {
        myMessage = myMessage + "\n\nCertificate request creation failed.";
        myMessage = myMessage + convertErrortoString(e);
        sdkSample.displayError(myMessage);
    }
}


Related topics

Submitting a certificate request and installing the certificate response
Working with certificates

 

 

Show:
© 2014 Microsoft