Delen via


CustomProtectedStream.CreateAsync method

Creates a CustomProtectedStream object based on the specified protection policy and a backing stream. The CustomProtectedStream can be used for both encrypting and decrypting content. If the backing stream already contains encrypted content, you can use the stream reading functions to decrypt the content. You can also use stream writing functions to encrypt the content and write the encrypted content to the backing stream.

[!Warning]
To avoid data loss and/or corruption, FlushAsync must be called if you modify the created stream or before object disposal.

Syntax

public:
static IAsyncOperation<CustomProtectedStream> CreateAsync(
  UserPolicy^ policy, 
  IRandomAccessStream^ stream, 
  unsigned long long contentStartPosition, 
  unsigned long long contentSize
)

Parameters

policy

Type: UserPolicy

The user policy to apply to protect the content.

stream

Type: IRandomAccessStream

The backing stream.

contentStartPosition

Type: UInt64

The start position of the stream.

contentSize

Type: UInt64

The size of the encrypted content.

Return value

Type: IAsyncOperation<CustomProtectedStream>

The asynchronous operation. Upon completion, IAsyncOperation.GetResults returns a CustomProtectedStream object that can be used to write content to the file.

Remarks

You specify a range (contentStartPosition, contentSize) where the encrypted content is located in the backing stream.

  • If there is no existing content in the backing stream (for example, if this is a new file), specify contentSize as zero.
  • If the existing content ends at the end of the stream, you can specify ulong.MaxValue for contentSize.
  • The contentSize parameter is needed only for the cases when there is non-encrypted app-specific content after the encrypted content. This is because the framework needs to know where the encrypted content ends when performing decryption.
  • The contentSize parameter is specified in terms of the encrypted content for example, it does include the size of the CBC padding.
  • If the range defined by the parameters contentStartPosition and contentSize is not empty (for example, contentSize != 0), it must address an entire segment of encrypted content; that is, it must start from block 0 and must have a final block in the CBC case or should be 16-byte aligned in the ECB case.

[!Warning]
To avoid data loss and/or corruption, FlushAsync must be called if you modify the created stream or before object disposal.

[!Warning]
This method must be called on a UI thread. Calling it on a worker thread may result in an unexpected behavior.

Requirements

Minimum supported client
None supported
Minimum supported server
None supported
Minimum supported phone
Windows Phone 8.1
Namespace
Microsoft::RightsManagement
Metadata
Microsoft.RightsManagement.winmd

See also

CustomProtectedStream