次の方法で共有


CustomProtectedInputStream.create synchronous method

Synchronously 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.

Signature

public static CustomProtectedInputStream create(
                                       UserPolicy userPolicy,
                                       InputStream inputStream,
                                       long protectedContentLength,
                                       Context applicationContext)
                             throws ProtectionException

Parameters

Name Datatype Notes
userPolicy
UserPolicy
The custom protection policy.
inputStream
InputStream
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.
protectedContentLength
long
The underlying length of the protected data contained within the stream.
applicationContext
Context

Returns

CustomProtectedInputStream

Throws

ProtectionException

Defined in

CustomProtectedInputStream.java

Supported Platforms

Minimum supported OS version
Android 4.0.3 (API level 15)

Remarks

This method is synchronous as 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.

This method works in a synchronous manner.