# MediaCodec.CryptoInfo

Added in[API level 16](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  
Summary:[Nested Classes](https://developer.android.com/reference/android/media/MediaCodec.CryptoInfo#nestedclasses)\|[Fields](https://developer.android.com/reference/android/media/MediaCodec.CryptoInfo#lfields)\|[Ctors](https://developer.android.com/reference/android/media/MediaCodec.CryptoInfo#pubctors)\|[Methods](https://developer.android.com/reference/android/media/MediaCodec.CryptoInfo#pubmethods)\|[Inherited Methods](https://developer.android.com/reference/android/media/MediaCodec.CryptoInfo#inhmethods)  

# MediaCodec.CryptoInfo

*** ** * ** ***

[Kotlin](https://developer.android.com/reference/kotlin/android/media/MediaCodec.CryptoInfo "View this page in Kotlin")\|Java

`
public
static
final

class
MediaCodec.CryptoInfo
`  
`

extends `[Object](https://developer.android.com/reference/java/lang/Object)`


``


`

|---|-------------------------------------|
| [java.lang.Object](https://developer.android.com/reference/java/lang/Object) ||
| ↳ | android.media.MediaCodec.CryptoInfo |

<br />

*** ** * ** ***

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](https://developer.android.com/reference/android/media/MediaCodec.CryptoInfo#numBytesOfClearData)can be null to indicate that all data is encrypted, and[numBytesOfEncryptedData](https://developer.android.com/reference/android/media/MediaCodec.CryptoInfo#numBytesOfEncryptedData)can be null to indicate that all data is clear. At least one of[numBytesOfClearData](https://developer.android.com/reference/android/media/MediaCodec.CryptoInfo#numBytesOfClearData)and[numBytesOfEncryptedData](https://developer.android.com/reference/android/media/MediaCodec.CryptoInfo#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".

<br />

### 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](https://developer.android.com/reference/android/media/MediaCodec.CryptoInfo#mode)field and the value set with[setPattern(Pattern)](https://developer.android.com/reference/android/media/MediaCodec.CryptoInfo#setPattern(android.media.MediaCodec.CryptoInfo.Pattern)). 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(Pattern)](https://developer.android.com/reference/android/media/MediaCodec.CryptoInfo#setPattern(android.media.MediaCodec.CryptoInfo.Pattern))is never called is all zeroes.

<br />

#### 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(Pattern)](https://developer.android.com/reference/android/media/MediaCodec.CryptoInfo#setPattern(android.media.MediaCodec.CryptoInfo.Pattern))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.

<br />

## Summary

|                                                                                                ### Nested classes                                                                                                ||
|----------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| ` class` | [MediaCodec.CryptoInfo.Pattern](https://developer.android.com/reference/android/media/MediaCodec.CryptoInfo.Pattern) Metadata describing an encryption pattern for the protected bytes in a subsample. |

|                                                                                                                                                                                                                                                                 ### Fields                                                                                                                                                                                                                                                                 ||
|------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| ` public byte[]` | [iv](https://developer.android.com/reference/android/media/MediaCodec.CryptoInfo#iv) A 16-byte initialization vector                                                                                                                                                                                                                                                                                                                                                                                                     |
| ` public byte[]` | [key](https://developer.android.com/reference/android/media/MediaCodec.CryptoInfo#key) A 16-byte key id                                                                                                                                                                                                                                                                                                                                                                                                                  |
| ` public int`    | [mode](https://developer.android.com/reference/android/media/MediaCodec.CryptoInfo#mode) The type of encryption that has been applied, see[MediaCodec.CRYPTO_MODE_UNENCRYPTED](https://developer.android.com/reference/android/media/MediaCodec#CRYPTO_MODE_UNENCRYPTED),[MediaCodec.CRYPTO_MODE_AES_CTR](https://developer.android.com/reference/android/media/MediaCodec#CRYPTO_MODE_AES_CTR)and[MediaCodec.CRYPTO_MODE_AES_CBC](https://developer.android.com/reference/android/media/MediaCodec#CRYPTO_MODE_AES_CBC) |
| ` public int[]`  | [numBytesOfClearData](https://developer.android.com/reference/android/media/MediaCodec.CryptoInfo#numBytesOfClearData) The number of leading unencrypted bytes in each subSample.                                                                                                                                                                                                                                                                                                                                        |
| ` public int[]`  | [numBytesOfEncryptedData](https://developer.android.com/reference/android/media/MediaCodec.CryptoInfo#numBytesOfEncryptedData) The number of trailing encrypted bytes in each subSample.                                                                                                                                                                                                                                                                                                                                 |
| ` public int`    | [numSubSamples](https://developer.android.com/reference/android/media/MediaCodec.CryptoInfo#numSubSamples) The number of subSamples that make up the buffer's contents.                                                                                                                                                                                                                                                                                                                                                  |

|                                              ### Public constructors                                              ||
|----------------------------------------------------------------------------------------------------------------|---|
| ` `[CryptoInfo](https://developer.android.com/reference/android/media/MediaCodec.CryptoInfo#CryptoInfo())`() ` |

|                                                                                                                                                                                                                                                                                        ### Public methods                                                                                                                                                                                                                                                                                         ||
|-------------------------------------------------------------------------------------------------------------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| ` `[MediaCodec.CryptoInfo.Pattern](https://developer.android.com/reference/android/media/MediaCodec.CryptoInfo.Pattern) | ` `[getPattern](https://developer.android.com/reference/android/media/MediaCodec.CryptoInfo#getPattern())`() ` Returns the[encryption pattern](https://developer.android.com/reference/android/media/MediaCodec.CryptoInfo.Pattern).                                                                                                                                                                                                                                     |
| ` void`                                                                                                                 | ` `[set](https://developer.android.com/reference/android/media/MediaCodec.CryptoInfo#set(int,%20int[],%20int[],%20byte[],%20byte[],%20int))`(int newNumSubSamples, int[] newNumBytesOfClearData, int[] newNumBytesOfEncryptedData, byte[] newKey, byte[] newIV, int newMode) ` Set the subsample count, clear/encrypted sizes, key, IV and mode fields of a[MediaCodec.CryptoInfo](https://developer.android.com/reference/android/media/MediaCodec.CryptoInfo)instance. |
| ` void`                                                                                                                 | ` `[setPattern](https://developer.android.com/reference/android/media/MediaCodec.CryptoInfo#setPattern(android.media.MediaCodec.CryptoInfo.Pattern))`(`[MediaCodec.CryptoInfo.Pattern](https://developer.android.com/reference/android/media/MediaCodec.CryptoInfo.Pattern)` newPattern) ` Set the encryption pattern on a[MediaCodec.CryptoInfo](https://developer.android.com/reference/android/media/MediaCodec.CryptoInfo)instance.                                  |
| ` `[String](https://developer.android.com/reference/java/lang/String)                                                   | ` `[toString](https://developer.android.com/reference/android/media/MediaCodec.CryptoInfo#toString())`() ` Returns a string representation of the object.                                                                                                                                                                                                                                                                                                                |

| ### Inherited methods |
|-----------------------|---|
| From class` `[java.lang.Object](https://developer.android.com/reference/java/lang/Object)` ` |--------------------------------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| | ` `[Object](https://developer.android.com/reference/java/lang/Object)          | ` `[clone](https://developer.android.com/reference/java/lang/Object#clone())`() ` Creates and returns a copy of this object.                                                                                                                                                      | | ` boolean`                                                                     | ` `[equals](https://developer.android.com/reference/java/lang/Object#equals(java.lang.Object))`(`[Object](https://developer.android.com/reference/java/lang/Object)` obj) ` Indicates whether some other object is "equal to" this one.                                           | | ` void`                                                                        | ` `[finalize](https://developer.android.com/reference/java/lang/Object#finalize())`() ` Called by the garbage collector on an object when garbage collection determines that there are no more references to the object.                                                          | | ` final `[Class](https://developer.android.com/reference/java/lang/Class)`<?>` | ` `[getClass](https://developer.android.com/reference/java/lang/Object#getClass())`() ` Returns the runtime class of this`Object`.                                                                                                                                                | | ` int`                                                                         | ` `[hashCode](https://developer.android.com/reference/java/lang/Object#hashCode())`() ` Returns a hash code value for the object.                                                                                                                                                 | | ` final void`                                                                  | ` `[notify](https://developer.android.com/reference/java/lang/Object#notify())`() ` Wakes up a single thread that is waiting on this object's monitor.                                                                                                                            | | ` final void`                                                                  | ` `[notifyAll](https://developer.android.com/reference/java/lang/Object#notifyAll())`() ` Wakes up all threads that are waiting on this object's monitor.                                                                                                                         | | ` `[String](https://developer.android.com/reference/java/lang/String)          | ` `[toString](https://developer.android.com/reference/java/lang/Object#toString())`() ` Returns a string representation of the object.                                                                                                                                            | | ` final void`                                                                  | ` `[wait](https://developer.android.com/reference/java/lang/Object#wait(long,%20int))`(long timeoutMillis, int nanos) ` Causes the current thread to wait until it is awakened, typically by being*notified* or*interrupted*, or until a certain amount of real time has elapsed. | | ` final void`                                                                  | ` `[wait](https://developer.android.com/reference/java/lang/Object#wait(long))`(long timeoutMillis) ` Causes the current thread to wait until it is awakened, typically by being*notified* or*interrupted*, or until a certain amount of real time has elapsed.                   | | ` final void`                                                                  | ` `[wait](https://developer.android.com/reference/java/lang/Object#wait())`() ` Causes the current thread to wait until it is awakened, typically by being*notified* or*interrupted*.                                                                                             | ||

## Fields

### iv

Added in[API level 16](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public byte[] iv
```

A 16-byte initialization vector

<br />

### key

Added in[API level 16](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public byte[] key
```

A 16-byte key id

<br />

### mode

Added in[API level 16](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public int mode
```

The type of encryption that has been applied, see[MediaCodec.CRYPTO_MODE_UNENCRYPTED](https://developer.android.com/reference/android/media/MediaCodec#CRYPTO_MODE_UNENCRYPTED),[MediaCodec.CRYPTO_MODE_AES_CTR](https://developer.android.com/reference/android/media/MediaCodec#CRYPTO_MODE_AES_CTR)and[MediaCodec.CRYPTO_MODE_AES_CBC](https://developer.android.com/reference/android/media/MediaCodec#CRYPTO_MODE_AES_CBC)

<br />

### numBytesOfClearData

Added in[API level 16](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public int[] numBytesOfClearData
```

The number of leading unencrypted bytes in each subSample. If null, all bytes are treated as encrypted and[numBytesOfEncryptedData](https://developer.android.com/reference/android/media/MediaCodec.CryptoInfo#numBytesOfEncryptedData)must be specified.

<br />

### numBytesOfEncryptedData

Added in[API level 16](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public int[] numBytesOfEncryptedData
```

The number of trailing encrypted bytes in each subSample. If null, all bytes are treated as clear and[numBytesOfClearData](https://developer.android.com/reference/android/media/MediaCodec.CryptoInfo#numBytesOfClearData)must be specified.

<br />

### numSubSamples

Added in[API level 16](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public int numSubSamples
```

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

<br />

## Public constructors

### CryptoInfo

```
public CryptoInfo ()
```

<br />

<br />

## Public methods

### getPattern

Added in[API level 31](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public MediaCodec.CryptoInfo.Pattern getPattern ()
```

Returns the[encryption pattern](https://developer.android.com/reference/android/media/MediaCodec.CryptoInfo.Pattern).

<br />

|                                                                         Returns                                                                          ||
|----------------------------------------------------------------------------------------------------------------------|------------------------------------|
| [MediaCodec.CryptoInfo.Pattern](https://developer.android.com/reference/android/media/MediaCodec.CryptoInfo.Pattern) | This value cannot be`null`. <br /> |

### set

Added in[API level 16](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public void set (int newNumSubSamples, 
                int[] newNumBytesOfClearData, 
                int[] newNumBytesOfEncryptedData, 
                byte[] newKey, 
                byte[] newIV, 
                int newMode)
```

Set the subsample count, clear/encrypted sizes, key, IV and mode fields of a[MediaCodec.CryptoInfo](https://developer.android.com/reference/android/media/MediaCodec.CryptoInfo)instance.

<br />

|                                Parameters                                ||
|------------------------------|--------------------------------------------|
| `newNumSubSamples`           | `int` <br />                               |
| `newNumBytesOfClearData`     | `int`: This value cannot be`null`. <br />  |
| `newNumBytesOfEncryptedData` | `int`: This value cannot be`null`. <br />  |
| `newKey`                     | `byte`: This value cannot be`null`. <br /> |
| `newIV`                      | `byte`: This value cannot be`null`. <br /> |
| `newMode`                    | `int` <br />                               |

### setPattern

Added in[API level 24](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public void setPattern (MediaCodec.CryptoInfo.Pattern newPattern)
```

Set the encryption pattern on a[MediaCodec.CryptoInfo](https://developer.android.com/reference/android/media/MediaCodec.CryptoInfo)instance. See[Pattern](https://developer.android.com/reference/android/media/MediaCodec.CryptoInfo.Pattern).

<br />

|                      Parameters                      ||
|--------------|----------------------------------------|
| `newPattern` | `MediaCodec.CryptoInfo.Pattern` <br /> |

### toString

Added in[API level 16](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public String toString ()
```

Returns a string representation of the object.

<br />

|                                                      Returns                                                      ||
|--------------------------------------------------------------------|-----------------------------------------------|
| [String](https://developer.android.com/reference/java/lang/String) | a string representation of the object. <br /> |