DataProtectionProvider.ProtectAsync | protectAsync method

Applies to Windows and Windows Phone

Asynchronously protects static data.

Syntax


dataProtectionProvider.protectAsync(data).done( /* Your success and error handlers */ );

Parameters

data

Type: IBuffer

Data to protect.

Return value

Type: IAsyncOperation<IBuffer>

Represents an asynchronous operation.

Remarks

You must call the DataProtectionProvider(String) constructor before calling this method.

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 protect static data.


public async Task<IBuffer> SampleProtectAsync(
    String strMsg,
    String strDescriptor,
    BinaryStringEncoding encoding)
{
    // Create a DataProtectionProvider object for the specified descriptor.
    DataProtectionProvider Provider = new DataProtectionProvider(strDescriptor);

    // Encode the plaintext input message to a buffer.
    encoding = BinaryStringEncoding.Utf8;
    IBuffer buffMsg = CryptographicBuffer.ConvertStringToBinary(strMsg, encoding);

    // Encrypt the message.
    IBuffer buffProtected = await Provider.ProtectAsync(buffMsg);

    // Execution of the SampleProtectAsync function resumes here
    // after the awaited task (Provider.ProtectAsync) completes.
    return buffProtected;
}


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

 

 

Show:
© 2014 Microsoft