Added in API level 16

CryptoInfo

class CryptoInfo
kotlin.Any
   ↳ android.media.MediaCodec.CryptoInfo

Metadata describing the structure of an encrypted input sample.

A buffer's data is considered to be partitioned into "subSamples". Each subSample starts with a run of plain, unencrypted bytes followed by a run of encrypted bytes. Either of these runs may be empty. If pattern encryption applies, each of the encrypted runs is encrypted only partly, according to a repeating pattern of "encrypt" and "skip" blocks. numBytesOfClearData can be null to indicate that all data is encrypted, and numBytesOfEncryptedData can be null to indicate that all data is clear. At least one of numBytesOfClearData and numBytesOfEncryptedData must be non-null.

This information encapsulates per-sample metadata as outlined in ISO/IEC FDIS 23001-7:2016 "Common encryption in ISO base media file format files".

ISO-CENC Schemes

ISO/IEC FDIS 23001-7:2016 defines four possible schemes by which media may be encrypted, corresponding to each possible combination of an AES mode with the presence or absence of patterned encryption.
  AES-CTR AES-CBC
Without Patterns cenc cbc1
With Patterns cens cbcs
For CryptoInfo, the scheme is selected implicitly by the combination of the mode field and the value set with setPattern. For the pattern, setting the pattern to all zeroes (that is, both blocksToEncrypt and blocksToSkip are zero) is interpreted as turning patterns off completely. A scheme that does not use patterns will be selected, either cenc or cbc1. Setting the pattern to any nonzero value will choose one of the pattern-supporting schemes, cens or cbcs. The default pattern if setPattern is never called is all zeroes.

HLS SAMPLE-AES Audio

HLS SAMPLE-AES audio is encrypted in a manner compatible with the cbcs scheme, except that it does not use patterned encryption. However, if setPattern is used to set the pattern to all zeroes, this will be interpreted as selecting the cbc1 scheme. The cbc1 scheme cannot successfully decrypt HLS SAMPLE-AES audio because of differences in how the IVs are handled. For this reason, it is recommended that a pattern of 1 encrypted block and 0 skip blocks be used with HLS SAMPLE-AES audio. This will trigger decryption to use cbcs mode while still decrypting every block.

Summary

Nested classes

Metadata describing an encryption pattern for the protected bytes in a subsample.

Public constructors

Public methods
MediaCodec.CryptoInfo.Pattern

Returns the encryption pattern.

Unit
set(newNumSubSamples: Int, newNumBytesOfClearData: IntArray, newNumBytesOfEncryptedData: IntArray, newKey: ByteArray, newIV: ByteArray, newMode: Int)

Set the subsample count, clear/encrypted sizes, key, IV and mode fields of a MediaCodec.CryptoInfo instance.

Unit

Set the encryption pattern on a MediaCodec.CryptoInfo instance.

String

Properties
ByteArray!

A 16-byte initialization vector

ByteArray!

A 16-byte key id

Int

The type of encryption that has been applied, see CRYPTO_MODE_UNENCRYPTED, CRYPTO_MODE_AES_CTR and CRYPTO_MODE_AES_CBC

IntArray!

The number of leading unencrypted bytes in each subSample.

IntArray!

The number of trailing encrypted bytes in each subSample.

Int

The number of subSamples that make up the buffer's contents.

Public constructors

CryptoInfo

CryptoInfo()

Public methods

getPattern

Added in API level 31
fun getPattern(): MediaCodec.CryptoInfo.Pattern

Returns the encryption pattern.

Return
MediaCodec.CryptoInfo.Pattern This value cannot be null.

set

Added in API level 16
fun set(
    newNumSubSamples: Int,
    newNumBytesOfClearData: IntArray,
    newNumBytesOfEncryptedData: IntArray,
    newKey: ByteArray,
    newIV: ByteArray,
    newMode: Int
): Unit

Set the subsample count, clear/encrypted sizes, key, IV and mode fields of a MediaCodec.CryptoInfo instance.

Parameters
newNumBytesOfClearData IntArray: This value cannot be null.
newNumBytesOfEncryptedData IntArray: This value cannot be null.
newKey ByteArray: This value cannot be null.
newIV ByteArray: This value cannot be null.

setPattern

Added in API level 24
fun setPattern(newPattern: MediaCodec.CryptoInfo.Pattern!): Unit

Set the encryption pattern on a MediaCodec.CryptoInfo instance. See Pattern.

toString

Added in API level 16
fun toString(): String
Return
String a string representation of the object.

Properties

iv

Added in API level 16
var iv: ByteArray!

A 16-byte initialization vector

key

Added in API level 16
var key: ByteArray!

A 16-byte key id

mode

Added in API level 16
var mode: Int

The type of encryption that has been applied, see CRYPTO_MODE_UNENCRYPTED, CRYPTO_MODE_AES_CTR and CRYPTO_MODE_AES_CBC

numBytesOfClearData

Added in API level 16
var numBytesOfClearData: IntArray!

The number of leading unencrypted bytes in each subSample. If null, all bytes are treated as encrypted and numBytesOfEncryptedData must be specified.

numBytesOfEncryptedData

Added in API level 16
var numBytesOfEncryptedData: IntArray!

The number of trailing encrypted bytes in each subSample. If null, all bytes are treated as clear and numBytesOfClearData must be specified.

numSubSamples

Added in API level 16
var numSubSamples: Int

The number of subSamples that make up the buffer's contents.