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.

DataProtectionProvider.DataProtectionProvider() constructor

Applies to Windows and Windows Phone

Constructor used for decryption operations. Use this constructor before calling the UnprotectAsync or UnprotectStreamAsync methods.

Syntax


var dataProtectionProvider = new Windows.Security.Cryptography.DataProtection.DataProtectionProvider();

Parameters

This constructor has no parameters.

Remarks

Use this constructor before starting a decryption operation. Do not use this constructor before starting an encryption operation. Use the DataProtectionProvider(String) method instead.

For security descriptors and SDDL strings, you must set the enterprise authentication capability in the manifest. The enterprise authentication capability is restricted to Windows Store apps built with company accounts, and is subject to additional onboarding validation. You should avoid the enterprise authentication capability unless it is absolutely necessary. For more information, see Registering for a Windows Store developer account.

For example, the following SID and SDDL providers require the enterprise authentication capability:

  • "SID=S-1-5-21-4392301 AND SID=S-1-5-21-3101812"
  • "SDDL=O:S-1-5-5-0-290724G:SYD:(A;;CCDC;;;S-1-5-5-0-290724)(A;;DC;;;WD)"

These providers do not require the enterprise authentication capability:

  • "LOCAL=user"
  • "LOCAL=machine"
  • "WEBCREDENTIALS=MyPasswordName"
  • "WEBCREDENTIALS=MyPasswordName,myweb.com"

Examples

The following example shows how to decrypt static data that was previously protected by using the ProtectAsync function.


public async Task<String> SampleUnprotectData(
    IBuffer buffProtected,
    BinaryStringEncoding encoding)
{
    // Create a DataProtectionProvider object.
    DataProtectionProvider Provider = new DataProtectionProvider();

    // Decrypt the protected message specified on input.
    IBuffer buffUnprotected = await Provider.UnprotectAsync(buffProtected);

    // Execution of the SampleUnprotectData method resumes here
    // after the awaited task (Provider.UnprotectAsync) completes
    // Convert the unprotected message from an IBuffer object to a string.
    String strClearText = CryptographicBuffer.ConvertBinaryToString(encoding, buffUnprotected);

    // Return the plaintext string.
    return strClearText;
}


The following example shows how to decrypt static data that was previously protected by using the ProtectStreamAsync function.


public async Task<String> SampleDataUnprotectStream(
    IBuffer buffProtected,
    BinaryStringEncoding encoding)
{
    // Create a DataProtectionProvider object.
    DataProtectionProvider Provider = new DataProtectionProvider();

    // Create a random access stream to contain the encrypted message.
    InMemoryRandomAccessStream inputData = new InMemoryRandomAccessStream();

    // Create a random access stream to contain the decrypted data.
    InMemoryRandomAccessStream unprotectedData = new InMemoryRandomAccessStream();

    // Retrieve an IOutputStream object and fill it with the input (encrypted) data.
    IOutputStream outputStream = inputData.GetOutputStreamAt(0);
    DataWriter writer = new DataWriter(outputStream);
    writer.WriteBuffer(buffProtected);
    await writer.StoreAsync();
    await outputStream.FlushAsync();

    // Retrieve an IInputStream object from which you can read the input (encrypted) data.
    IInputStream source = inputData.GetInputStreamAt(0);

    // Retrieve an IOutputStream object and fill it with decrypted data.
    IOutputStream dest = unprotectedData.GetOutputStreamAt(0);
    await Provider.UnprotectStreamAsync(source, dest);
    await dest.FlushAsync();

    // Write the decrypted data to an IBuffer object.
    DataReader reader2 = new DataReader(unprotectedData.GetInputStreamAt(0));
    await reader2.LoadAsync((uint)unprotectedData.Size);
    IBuffer buffUnprotectedData = reader2.ReadBuffer((uint)unprotectedData.Size);

    // Convert the IBuffer object to a string using the same encoding that was
    // used previously to conver the plaintext string (before encryption) to an
    // IBuffer object.
    String strUnprotected = CryptographicBuffer.ConvertBinaryToString(encoding, buffUnprotectedData);

    // Return the decrypted data.
    return strUnprotected;
}


Requirements

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.DataProtection
Windows::Security::Cryptography::DataProtection [C++]

Metadata

Windows.winmd

See also

DataProtectionProvider
DataProtectionProvider(String)

 

 

Show:
© 2014 Microsoft. All rights reserved.