CustomProtectedInputStream.create asynchronous method

Asynchronously creates an InputStream for reading protected content.

Opens the specified serialized policy and creates a protected stream that can be used to decrypt the actual content. For more information, see the Remarks section of this topic.


public static IAsyncControl create(
                                       UserPolicy userPolicy,
                                       InputStream inputStream,
                                       long protectedContentLength,
                                       CreationCallback<CustomProtectedInputStream> callback)
                             throws InvalidParameterException


Name Datatype Notes
The custom protection policy.
The input stream with the protected content.
The next bytes of available data in inputStream (i.e., those returned via the next call to inputStream.Read()) should contain the beginning of the stream's protected content. inputStream should have protectedContentLength bytes of contiguous protected content available.
The underlying length of the protected data contained within the stream.


IAsyncControl if an async operation is in progress else null is returned.


InvalidParameterException if no callback is available then onFailure can be called.

Defined in

Supported Platforms

Minimum supported OS version
Android 4.0.3 (API level 15)


This method is asynchronous because it may require server / client communication. Your app specifies a current stream offset to protectedContentLength where the encrypted content is located in the backing stream.

If the range defined by the parameters current stream offset to protectedContentLength is not empty (i.e., protectedContentLength != 0), it must address an entire segment of encrypted content (i.e. it must start from block 0 (zero) and must have a final block in CBC case, or should be 16 bytes aligned in ECB case).

If the existing content ends at the end of the InputStream, your app can specify Long.MAX_VALUE as protectedContentLength.

The protectedContentLength parameter is needed only for the cases when there is a non-encrypted app specific content after the encrypted content (Multiple segments of protected data). When decrypting it, we need to know where the encrypted content ends. The protectedContentLength parameter is specified in terms of the encrypted content, i.e. it includes the size of the CBC padding.

Your app can use getEncryptedContentLength to determine the size of the encrypted content given the size of the original content.