Added in [API level 18](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels) Summary: [Methods](https://developer.android.com/reference/android/media/MediaDrm.CryptoSession#pubmethods) \| [Inherited Methods](https://developer.android.com/reference/android/media/MediaDrm.CryptoSession#inhmethods)

# MediaDrm.CryptoSession

*** ** * ** ***


`
public

final

class
MediaDrm.CryptoSession
`


`

extends https://developer.android.com/reference/java/lang/Object


`

`


`

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

<br />

*** ** * ** ***

In addition to supporting decryption of DASH Common Encrypted Media, the
MediaDrm APIs provide the ability to securely deliver session keys from
an operator's session key server to a client device, based on the factory-installed
root of trust, and then perform encrypt, decrypt, sign and verify operations
with the session key on arbitrary user data.


The CryptoSession class implements generic encrypt/decrypt/sign/verify methods
based on the established session keys. These keys are exchanged using the
getKeyRequest/provideKeyResponse methods.


Applications of this capability could include securing various types of
purchased or private content, such as applications, books and other media,
photos or media delivery protocols.


Operators can create session key servers that are functionally similar to a
license key server, except that instead of receiving license key requests and
providing encrypted content keys which are used specifically to decrypt A/V media
content, the session key server receives session key requests and provides
encrypted session keys which can be used for general purpose crypto operations.


A CryptoSession is obtained using `https://developer.android.com/reference/android/media/MediaDrm#getCryptoSession(byte[],%20java.lang.String,%20java.lang.String)`

## Summary

| ### Public methods ||
|---|---|
| ` byte[]` | ` https://developer.android.com/reference/android/media/MediaDrm.CryptoSession#decrypt(byte[],%20byte[],%20byte[])(byte[] keyid, byte[] input, byte[] iv) ` Decrypt data using the CryptoSessions's cipher algorithm |
| ` byte[]` | ` https://developer.android.com/reference/android/media/MediaDrm.CryptoSession#encrypt(byte[],%20byte[],%20byte[])(byte[] keyid, byte[] input, byte[] iv) ` Encrypt data using the CryptoSession's cipher algorithm |
| ` byte[]` | ` https://developer.android.com/reference/android/media/MediaDrm.CryptoSession#sign(byte[],%20byte[])(byte[] keyid, byte[] message) ` Sign data using the CryptoSessions's mac algorithm. |
| ` boolean` | ` https://developer.android.com/reference/android/media/MediaDrm.CryptoSession#verify(byte[],%20byte[],%20byte[])(byte[] keyid, byte[] message, byte[] signature) ` Verify a signature using the CryptoSessions's mac algorithm. |

| ### Inherited methods |
|---|---|
| From class ` https://developer.android.com/reference/java/lang/Object ` |---|---| | ` https://developer.android.com/reference/java/lang/Object` | ` https://developer.android.com/reference/java/lang/Object#clone()() ` Creates and returns a copy of this object. | | ` boolean` | ` https://developer.android.com/reference/java/lang/Object#equals(java.lang.Object)(https://developer.android.com/reference/java/lang/Object obj) ` Indicates whether some other object is "equal to" this one. | | ` void` | ` 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 https://developer.android.com/reference/java/lang/Class<?>` | ` https://developer.android.com/reference/java/lang/Object#getClass()() ` Returns the runtime class of this `Object`. | | ` int` | ` https://developer.android.com/reference/java/lang/Object#hashCode()() ` Returns a hash code value for the object. | | ` final void` | ` https://developer.android.com/reference/java/lang/Object#notify()() ` Wakes up a single thread that is waiting on this object's monitor. | | ` final void` | ` https://developer.android.com/reference/java/lang/Object#notifyAll()() ` Wakes up all threads that are waiting on this object's monitor. | | ` https://developer.android.com/reference/java/lang/String` | ` https://developer.android.com/reference/java/lang/Object#toString()() ` Returns a string representation of the object. | | ` final void` | ` 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` | ` 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` | ` 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*. | ||

## Public methods

### decrypt

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

```
public byte[] decrypt (byte[] keyid, 
                byte[] input, 
                byte[] iv)
```

Decrypt data using the CryptoSessions's cipher algorithm

<br />

| Parameters ||
|---|---|
| `keyid` | `byte`: specifies which key to use. This value cannot be `null`. <br /> |
| `input` | `byte`: the data to encrypt. This value cannot be `null`. <br /> |
| `iv` | `byte`: the initialization vector to use for the cipher. This value cannot be `null`. <br /> |

| Returns ||
|---|---|
| `byte[]` | This value cannot be `null`. <br /> |

### encrypt

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

```
public byte[] encrypt (byte[] keyid, 
                byte[] input, 
                byte[] iv)
```

Encrypt data using the CryptoSession's cipher algorithm

<br />

| Parameters ||
|---|---|
| `keyid` | `byte`: specifies which key to use. This value cannot be `null`. <br /> |
| `input` | `byte`: the data to encrypt. This value cannot be `null`. <br /> |
| `iv` | `byte`: the initialization vector to use for the cipher. This value cannot be `null`. <br /> |

| Returns ||
|---|---|
| `byte[]` | This value cannot be `null`. <br /> |

### sign

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

```
public byte[] sign (byte[] keyid, 
                byte[] message)
```

Sign data using the CryptoSessions's mac algorithm.

<br />

| Parameters ||
|---|---|
| `keyid` | `byte`: specifies which key to use. This value cannot be `null`. <br /> |
| `message` | `byte`: the data for which a signature is to be computed. This value cannot be `null`. <br /> |

| Returns ||
|---|---|
| `byte[]` | This value cannot be `null`. <br /> |

### verify

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

```
public boolean verify (byte[] keyid, 
                byte[] message, 
                byte[] signature)
```

Verify a signature using the CryptoSessions's mac algorithm. Return true
if the signatures match, false if they do no.

<br />

| Parameters ||
|---|---|
| `keyid` | `byte`: specifies which key to use. This value cannot be `null`. <br /> |
| `message` | `byte`: the data to verify. This value cannot be `null`. <br /> |
| `signature` | `byte`: the reference signature which will be compared with the computed signature. This value cannot be `null`. <br /> |

| Returns ||
|---|---|
| `boolean` | <br /> |