Creazione di una richiesta di certificato (app di Windows Runtime scritte in JavaScript e HTML)

[ Questo articolo è rivolto agli sviluppatori per Windows 8.x e Windows Phone 8.x che realizzano app di Windows Runtime. Gli sviluppatori che usano Windows 10 possono vedere Documentazione aggiornata ]

Per creare una richiesta di certificato, devi prima creare un oggetto CertificateRequestProperties e definire le proprietà del certificato. Per impostazione predefinita, il costruttore imposta le proprietà seguenti:

Proprietà Valore predefinito

Subject

Stringa vuota

KeyAlgorithmName

KeyAlgorithmNames.RSA

KeySize

KeySize.RSA2048

FriendlyName

Stringa vuota

HashAlgorithmName

HashAlgorithmNames.Sha256

Exportable

ExportOption.NotExportable

KeyUsages

EnrollKeyUsage.Signing

KeyProtectionLevel

KeyProtectionLevel.NoConsent

KeyStorageProviderName

KeystorageProviderNames.SoftwareKeyStorageProvider

Indica il "Provider di archiviazione chiavi per software Microsoft"

 

Per creare la richiesta, devi chiamare il metodo CreateRequestAsync come nell'esempio seguente.


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);
    }
}

Argomenti correlati

Invio di una richiesta di certificato e installazione della risposta

Uso dei certificati