# BiometricPrompt.CryptoObject

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

# CryptoObject

*** ** * ** ***

Kotlin\|[Java](https://developer.android.com/reference/android/hardware/biometrics/BiometricPrompt.CryptoObject "View this page in Java")  

```
class CryptoObject
```

|---|----------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| [kotlin.Any](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-any/index.html)                                                                                       ||
| ↳ | [android.hardware.biometrics.BiometricPrompt.CryptoObject](https://developer.android.com/reference/kotlin/android/hardware/biometrics/BiometricPrompt.CryptoObject#) |

A wrapper class for the cryptographic operations supported by BiometricPrompt.

Currently the framework supports[Signature](https://developer.android.com/reference/kotlin/java/security/Signature.html#),[Cipher](https://developer.android.com/reference/kotlin/javax/crypto/Cipher.html#),[Mac](https://developer.android.com/reference/kotlin/javax/crypto/Mac.html#),[IdentityCredential](https://developer.android.com/reference/kotlin/android/security/identity/IdentityCredential.html#),[PresentationSession](https://developer.android.com/reference/kotlin/android/security/identity/PresentationSession.html#)and[KeyAgreement](https://developer.android.com/reference/kotlin/javax/crypto/KeyAgreement.html#).

Cryptographic operations in Android can be split into two categories: auth-per-use and time-based. This is specified during key creation via the timeout parameter of the`setUserAuthenticationParameters(int, int)`method of .

CryptoObjects are used to unlock auth-per-use keys via[BiometricPrompt.authenticate(CryptoObject, CancellationSignal, Executor,](https://developer.android.com/reference/kotlin/android/hardware/biometrics/BiometricPrompt#authenticate(android.hardware.biometrics.BiometricPrompt.CryptoObject,%20android.os.CancellationSignal,%20java.util.concurrent.Executor,%20android.hardware.biometrics.BiometricPrompt.AuthenticationCallback)), whereas time-based keys are unlocked for their specified duration any time the user authenticates with the specified authenticators (e.g. unlocking keyguard). If a time-based key is not available for use (i.e. none of the allowed authenticators have been unlocked recently), applications can prompt the user to authenticate via[BiometricPrompt.authenticate(CancellationSignal, Executor, AuthenticationCallback)](https://developer.android.com/reference/kotlin/android/hardware/biometrics/BiometricPrompt#authenticate(android.os.CancellationSignal,%20java.util.concurrent.Executor,%20android.hardware.biometrics.BiometricPrompt.AuthenticationCallback))

## Summary

|                                                                                                                                                                                                                              Public constructors                                                                                                                                                                                                                               ||
|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|---|
| [CryptoObject](https://developer.android.com/reference/kotlin/android/hardware/biometrics/BiometricPrompt.CryptoObject#CryptoObject(android.security.identity.IdentityCredential))`(`credential:` `[IdentityCredential](https://developer.android.com/reference/kotlin/android/security/identity/IdentityCredential.html#)`)` Create from a[IdentityCredential](https://developer.android.com/reference/kotlin/android/security/identity/IdentityCredential.html#)object.   |
| [CryptoObject](https://developer.android.com/reference/kotlin/android/hardware/biometrics/BiometricPrompt.CryptoObject#CryptoObject(android.security.identity.PresentationSession))`(`session:` `[PresentationSession](https://developer.android.com/reference/kotlin/android/security/identity/PresentationSession.html#)`)` Create from a[PresentationSession](https://developer.android.com/reference/kotlin/android/security/identity/PresentationSession.html#)object. |
| [CryptoObject](https://developer.android.com/reference/kotlin/android/hardware/biometrics/BiometricPrompt.CryptoObject#CryptoObject(java.security.Signature))`(`signature:` `[Signature](https://developer.android.com/reference/kotlin/java/security/Signature.html#)`)` Create from a[Signature](https://developer.android.com/reference/kotlin/java/security/Signature.html#)object.                                                                                     |
| [CryptoObject](https://developer.android.com/reference/kotlin/android/hardware/biometrics/BiometricPrompt.CryptoObject#CryptoObject(javax.crypto.Cipher))`(`cipher:` `[Cipher](https://developer.android.com/reference/kotlin/javax/crypto/Cipher.html#)`)` Create from a[Cipher](https://developer.android.com/reference/kotlin/javax/crypto/Cipher.html#)object.                                                                                                          |
| [CryptoObject](https://developer.android.com/reference/kotlin/android/hardware/biometrics/BiometricPrompt.CryptoObject#CryptoObject(javax.crypto.KeyAgreement))`(`keyAgreement:` `[KeyAgreement](https://developer.android.com/reference/kotlin/javax/crypto/KeyAgreement.html#)`)` Create from a[KeyAgreement](https://developer.android.com/reference/kotlin/javax/crypto/KeyAgreement.html#)object.                                                                      |
| [CryptoObject](https://developer.android.com/reference/kotlin/android/hardware/biometrics/BiometricPrompt.CryptoObject#CryptoObject(javax.crypto.Mac))`(`mac:` `[Mac](https://developer.android.com/reference/kotlin/javax/crypto/Mac.html#)`)` Create from a[Mac](https://developer.android.com/reference/kotlin/javax/crypto/Mac.html#)object.                                                                                                                            |
| [CryptoObject](https://developer.android.com/reference/kotlin/android/hardware/biometrics/BiometricPrompt.CryptoObject#CryptoObject(kotlin.Long))`(`operationHandle:` `[Long](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-long/index.html)`)` Create from an operation handle.                                                                                                                                                                                     |

|                                                                                                                                                                                                         Public methods                                                                                                                                                                                                         ||
|----------------------------------------------------------------------------------------------------------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| [Cipher](https://developer.android.com/reference/kotlin/javax/crypto/Cipher.html#)?                                        | [getCipher](https://developer.android.com/reference/kotlin/android/hardware/biometrics/BiometricPrompt.CryptoObject#getCipher())`()` Get[Cipher](https://developer.android.com/reference/kotlin/javax/crypto/Cipher.html#)object.                                                                  |
| [IdentityCredential](https://developer.android.com/reference/kotlin/android/security/identity/IdentityCredential.html#)?   | [getIdentityCredential](https://developer.android.com/reference/kotlin/android/hardware/biometrics/BiometricPrompt.CryptoObject#getIdentityCredential())`()` Get[IdentityCredential](https://developer.android.com/reference/kotlin/android/security/identity/IdentityCredential.html#)object.     |
| [KeyAgreement](https://developer.android.com/reference/kotlin/javax/crypto/KeyAgreement.html#)?                            | [getKeyAgreement](https://developer.android.com/reference/kotlin/android/hardware/biometrics/BiometricPrompt.CryptoObject#getKeyAgreement())`()` Get[KeyAgreement](https://developer.android.com/reference/kotlin/javax/crypto/KeyAgreement.html#)object.                                          |
| [Mac](https://developer.android.com/reference/kotlin/javax/crypto/Mac.html#)?                                              | [getMac](https://developer.android.com/reference/kotlin/android/hardware/biometrics/BiometricPrompt.CryptoObject#getMac())`()` Get[Mac](https://developer.android.com/reference/kotlin/javax/crypto/Mac.html#)object.                                                                              |
| [Long](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-long/index.html)                                               | [getOperationHandle](https://developer.android.com/reference/kotlin/android/hardware/biometrics/BiometricPrompt.CryptoObject#getOperationHandle())`()` Returns the`operationHandle`associated with this object or 0 if none.                                                                       |
| [PresentationSession](https://developer.android.com/reference/kotlin/android/security/identity/PresentationSession.html#)? | [getPresentationSession](https://developer.android.com/reference/kotlin/android/hardware/biometrics/BiometricPrompt.CryptoObject#getPresentationSession())`()` Get[PresentationSession](https://developer.android.com/reference/kotlin/android/security/identity/PresentationSession.html#)object. |
| [Signature](https://developer.android.com/reference/kotlin/java/security/Signature.html#)?                                 | [getSignature](https://developer.android.com/reference/kotlin/android/hardware/biometrics/BiometricPrompt.CryptoObject#getSignature())`()` Get[Signature](https://developer.android.com/reference/kotlin/java/security/Signature.html#)object.                                                     |

## Public constructors

### CryptoObject

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

```
CryptoObject(credential: IdentityCredential)
```

**Deprecated:** *Use[PresentationSession](https://developer.android.com/reference/kotlin/android/security/identity/PresentationSession.html#)instead of[IdentityCredential](https://developer.android.com/reference/kotlin/android/security/identity/IdentityCredential.html#).*

Create from a[IdentityCredential](https://developer.android.com/reference/kotlin/android/security/identity/IdentityCredential.html#)object.

|                                                                                                                                            Parameters                                                                                                                                             ||
|--------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `credential` | [IdentityCredential](https://developer.android.com/reference/kotlin/android/security/identity/IdentityCredential.html#):a[IdentityCredential](https://developer.android.com/reference/kotlin/android/security/identity/IdentityCredential.html#)object. This value cannot be`null`. |

### CryptoObject

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

```
CryptoObject(session: PresentationSession)
```

Create from a[PresentationSession](https://developer.android.com/reference/kotlin/android/security/identity/PresentationSession.html#)object.

|                                                                                                                                             Parameters                                                                                                                                             ||
|-----------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `session` | [PresentationSession](https://developer.android.com/reference/kotlin/android/security/identity/PresentationSession.html#):a[PresentationSession](https://developer.android.com/reference/kotlin/android/security/identity/PresentationSession.html#)object. This value cannot be`null`. |

### CryptoObject

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

```
CryptoObject(signature: Signature)
```

Create from a[Signature](https://developer.android.com/reference/kotlin/java/security/Signature.html#)object.

|                                                                                                              Parameters                                                                                                              ||
|-------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `signature` | [Signature](https://developer.android.com/reference/kotlin/java/security/Signature.html#):a[Signature](https://developer.android.com/reference/kotlin/java/security/Signature.html#)object. This value cannot be`null`. |

### CryptoObject

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

```
CryptoObject(cipher: Cipher)
```

Create from a[Cipher](https://developer.android.com/reference/kotlin/javax/crypto/Cipher.html#)object.

|                                                                                                     Parameters                                                                                                      ||
|----------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `cipher` | [Cipher](https://developer.android.com/reference/kotlin/javax/crypto/Cipher.html#):a[Cipher](https://developer.android.com/reference/kotlin/javax/crypto/Cipher.html#)object. This value cannot be`null`. |

### CryptoObject

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

```
CryptoObject(keyAgreement: KeyAgreement)
```

Create from a[KeyAgreement](https://developer.android.com/reference/kotlin/javax/crypto/KeyAgreement.html#)object.

|                                                                                                                    Parameters                                                                                                                     ||
|----------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `keyAgreement` | [KeyAgreement](https://developer.android.com/reference/kotlin/javax/crypto/KeyAgreement.html#):a[KeyAgreement](https://developer.android.com/reference/kotlin/javax/crypto/KeyAgreement.html#)object. This value cannot be`null`. |

### CryptoObject

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

```
CryptoObject(mac: Mac)
```

Create from a[Mac](https://developer.android.com/reference/kotlin/javax/crypto/Mac.html#)object.

|                                                                                              Parameters                                                                                              ||
|-------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `mac` | [Mac](https://developer.android.com/reference/kotlin/javax/crypto/Mac.html#):a[Mac](https://developer.android.com/reference/kotlin/javax/crypto/Mac.html#)object. This value cannot be`null`. |

### CryptoObject

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

```
CryptoObject(operationHandle: Long)
```

Create from an operation handle.

|                                                                    Parameters                                                                     ||
|-------------------|--------------------------------------------------------------------------------------------------------------------------------|
| `operationHandle` | [Long](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-long/index.html):the operation handle associated with this object. |

**See Also**

- [android.hardware.biometrics.BiometricPrompt.CryptoObject#getOperationHandle()](https://developer.android.com/reference/kotlin/android/hardware/biometrics/BiometricPrompt.CryptoObject#getOperationHandle())

## Public methods

### getCipher

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

```
fun getCipher(): Cipher?
```

Get[Cipher](https://developer.android.com/reference/kotlin/javax/crypto/Cipher.html#)object.

|                                                                                                       Return                                                                                                       ||
|-------------------------------------------------------------------------------------|-------------------------------------------------------------------------------------------------------------------------------|
| [Cipher](https://developer.android.com/reference/kotlin/javax/crypto/Cipher.html#)? | [Cipher](https://developer.android.com/reference/kotlin/javax/crypto/Cipher.html#)object or null if this doesn't contain one. |

### getIdentityCredential

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

```
fun getIdentityCredential(): IdentityCredential?
```

**Deprecated:** *Use[PresentationSession](https://developer.android.com/reference/kotlin/android/security/identity/PresentationSession.html#)instead of[IdentityCredential](https://developer.android.com/reference/kotlin/android/security/identity/IdentityCredential.html#).*

Get[IdentityCredential](https://developer.android.com/reference/kotlin/android/security/identity/IdentityCredential.html#)object.

|                                                                                                                                            Return                                                                                                                                            ||
|--------------------------------------------------------------------------------------------------------------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| [IdentityCredential](https://developer.android.com/reference/kotlin/android/security/identity/IdentityCredential.html#)? | [IdentityCredential](https://developer.android.com/reference/kotlin/android/security/identity/IdentityCredential.html#)object or null if this doesn't contain one. |

### getKeyAgreement

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

```
fun getKeyAgreement(): KeyAgreement?
```

Get[KeyAgreement](https://developer.android.com/reference/kotlin/javax/crypto/KeyAgreement.html#)object.

|                                                                                                                   Return                                                                                                                   ||
|-------------------------------------------------------------------------------------------------|-------------------------------------------------------------------------------------------------------------------------------------------|
| [KeyAgreement](https://developer.android.com/reference/kotlin/javax/crypto/KeyAgreement.html#)? | [KeyAgreement](https://developer.android.com/reference/kotlin/javax/crypto/KeyAgreement.html#)object or null if this doesn't contain one. |

### getMac

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

```
fun getMac(): Mac?
```

Get[Mac](https://developer.android.com/reference/kotlin/javax/crypto/Mac.html#)object.

|                                                                                                 Return                                                                                                 ||
|-------------------------------------------------------------------------------|-------------------------------------------------------------------------------------------------------------------------|
| [Mac](https://developer.android.com/reference/kotlin/javax/crypto/Mac.html#)? | [Mac](https://developer.android.com/reference/kotlin/javax/crypto/Mac.html#)object or null if this doesn't contain one. |

### getOperationHandle

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

```
fun getOperationHandle(): Long
```

Returns the`operationHandle`associated with this object or 0 if none. The`operationHandle`is the underlying identifier associated with the`CryptoObject`.

The`operationHandle`can be used to reconstruct a`CryptoObject`instance. This is useful for any cross-process communication as the`CryptoObject`class is not[android.os.Parcelable](https://developer.android.com/reference/kotlin/android/os/Parcelable.html#). Hence, if the`CryptoObject`is constructed in one process, and needs to be propagated to another process, before calling the[BiometricPrompt.authenticate(CryptoObject, CancellationSignal, Executor,](https://developer.android.com/reference/kotlin/android/hardware/biometrics/BiometricPrompt#authenticate(android.hardware.biometrics.BiometricPrompt.CryptoObject,%20android.os.CancellationSignal,%20java.util.concurrent.Executor,%20android.hardware.biometrics.BiometricPrompt.AuthenticationCallback))API in the second process, the recommendation is to retrieve the`operationHandle`using this API, and then reconstruct the`CryptoObject`using the constructor that takes in an`operationHandle`, and pass that in to the`authenticate`API mentioned above.  

### getPresentationSession

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

```
fun getPresentationSession(): PresentationSession?
```

Get[PresentationSession](https://developer.android.com/reference/kotlin/android/security/identity/PresentationSession.html#)object.

|                                                                                                                                              Return                                                                                                                                              ||
|----------------------------------------------------------------------------------------------------------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| [PresentationSession](https://developer.android.com/reference/kotlin/android/security/identity/PresentationSession.html#)? | [PresentationSession](https://developer.android.com/reference/kotlin/android/security/identity/PresentationSession.html#)object or null if this doesn't contain one. |

### getSignature

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

```
fun getSignature(): Signature?
```

Get[Signature](https://developer.android.com/reference/kotlin/java/security/Signature.html#)object.

|                                                                                                              Return                                                                                                              ||
|--------------------------------------------------------------------------------------------|--------------------------------------------------------------------------------------------------------------------------------------|
| [Signature](https://developer.android.com/reference/kotlin/java/security/Signature.html#)? | [Signature](https://developer.android.com/reference/kotlin/java/security/Signature.html#)object or null if this doesn't contain one. |