Added in [API level 28](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels) Summary: [Ctors](https://developer.android.com/reference/android/hardware/biometrics/BiometricPrompt.CryptoObject#pubctors) \| [Methods](https://developer.android.com/reference/android/hardware/biometrics/BiometricPrompt.CryptoObject#pubmethods) \| [Inherited Methods](https://developer.android.com/reference/android/hardware/biometrics/BiometricPrompt.CryptoObject#inhmethods)

# BiometricPrompt.CryptoObject

*** ** * ** ***

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


`
public
static
final

class
BiometricPrompt.CryptoObject
`


`

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


`

`


`

|---|---|
| [java.lang.Object](https://developer.android.com/reference/java/lang/Object) ||
| ↳ | android.hardware.biometrics.BiometricPrompt.CryptoObject |

<br />

*** ** * ** ***

A wrapper class for the cryptographic operations supported by BiometricPrompt.

Currently the framework supports `https://developer.android.com/reference/java/security/Signature`, `https://developer.android.com/reference/javax/crypto/Cipher`, `https://developer.android.com/reference/javax/crypto/Mac`,
`https://developer.android.com/reference/android/security/identity/IdentityCredential`, `https://developer.android.com/reference/android/security/identity/PresentationSession` and `https://developer.android.com/reference/javax/crypto/KeyAgreement`.

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 `https://developer.android.com/reference/android/security/keystore/KeyGenParameterSpec.Builder`.

CryptoObjects are used to unlock auth-per-use keys via
`https://developer.android.com/reference/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
`https://developer.android.com/reference/android/hardware/biometrics/BiometricPrompt#authenticate(android.os.CancellationSignal,%20java.util.concurrent.Executor,%20android.hardware.biometrics.BiometricPrompt.AuthenticationCallback)`
**See also:**

- `https://developer.android.com/reference/android/hardware/biometrics/BiometricPrompt.Builder#setAllowedAuthenticators(int)`

## Summary

| ### Public constructors ||
|---|---|
| ` https://developer.android.com/reference/android/hardware/biometrics/BiometricPrompt.CryptoObject#CryptoObject(android.security.identity.IdentityCredential)(https://developer.android.com/reference/android/security/identity/IdentityCredential credential) ` *This constructor is deprecated. Use `https://developer.android.com/reference/android/security/identity/PresentationSession` instead of `https://developer.android.com/reference/android/security/identity/IdentityCredential`.* |
| ` https://developer.android.com/reference/android/hardware/biometrics/BiometricPrompt.CryptoObject#CryptoObject(android.security.identity.PresentationSession)(https://developer.android.com/reference/android/security/identity/PresentationSession session) ` Create from a `https://developer.android.com/reference/android/security/identity/PresentationSession` object. |
| ` https://developer.android.com/reference/android/hardware/biometrics/BiometricPrompt.CryptoObject#CryptoObject(java.security.Signature)(https://developer.android.com/reference/java/security/Signature signature) ` Create from a `https://developer.android.com/reference/java/security/Signature` object. |
| ` https://developer.android.com/reference/android/hardware/biometrics/BiometricPrompt.CryptoObject#CryptoObject(javax.crypto.Cipher)(https://developer.android.com/reference/javax/crypto/Cipher cipher) ` Create from a `https://developer.android.com/reference/javax/crypto/Cipher` object. |
| ` https://developer.android.com/reference/android/hardware/biometrics/BiometricPrompt.CryptoObject#CryptoObject(javax.crypto.KeyAgreement)(https://developer.android.com/reference/javax/crypto/KeyAgreement keyAgreement) ` Create from a `https://developer.android.com/reference/javax/crypto/KeyAgreement` object. |
| ` https://developer.android.com/reference/android/hardware/biometrics/BiometricPrompt.CryptoObject#CryptoObject(javax.crypto.Mac)(https://developer.android.com/reference/javax/crypto/Mac mac) ` Create from a `https://developer.android.com/reference/javax/crypto/Mac` object. |
| ` https://developer.android.com/reference/android/hardware/biometrics/BiometricPrompt.CryptoObject#CryptoObject(long)(long operationHandle) ` Create from an operation handle. |

| ### Public methods ||
|---|---|
| ` https://developer.android.com/reference/javax/crypto/Cipher` | ` https://developer.android.com/reference/android/hardware/biometrics/BiometricPrompt.CryptoObject#getCipher()() ` Get `https://developer.android.com/reference/javax/crypto/Cipher` object. |
| ` https://developer.android.com/reference/android/security/identity/IdentityCredential` | ` https://developer.android.com/reference/android/hardware/biometrics/BiometricPrompt.CryptoObject#getIdentityCredential()() ` *This method was deprecated in API level 33. Use `https://developer.android.com/reference/android/security/identity/PresentationSession` instead of `https://developer.android.com/reference/android/security/identity/IdentityCredential`.* |
| ` https://developer.android.com/reference/javax/crypto/KeyAgreement` | ` https://developer.android.com/reference/android/hardware/biometrics/BiometricPrompt.CryptoObject#getKeyAgreement()() ` Get `https://developer.android.com/reference/javax/crypto/KeyAgreement` object. |
| ` https://developer.android.com/reference/javax/crypto/Mac` | ` https://developer.android.com/reference/android/hardware/biometrics/BiometricPrompt.CryptoObject#getMac()() ` Get `https://developer.android.com/reference/javax/crypto/Mac` object. |
| ` long` | ` https://developer.android.com/reference/android/hardware/biometrics/BiometricPrompt.CryptoObject#getOperationHandle()() ` Returns the `operationHandle` associated with this object or 0 if none. |
| ` https://developer.android.com/reference/android/security/identity/PresentationSession` | ` https://developer.android.com/reference/android/hardware/biometrics/BiometricPrompt.CryptoObject#getPresentationSession()() ` Get `https://developer.android.com/reference/android/security/identity/PresentationSession` object. |
| ` https://developer.android.com/reference/java/security/Signature` | ` https://developer.android.com/reference/android/hardware/biometrics/BiometricPrompt.CryptoObject#getSignature()() ` Get `https://developer.android.com/reference/java/security/Signature` object. |

| ### 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 constructors

### CryptoObject

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

```
public CryptoObject (IdentityCredential credential)
```


**This constructor is deprecated.**   

Use `https://developer.android.com/reference/android/security/identity/PresentationSession` instead of `https://developer.android.com/reference/android/security/identity/IdentityCredential`.

Create from a `https://developer.android.com/reference/android/security/identity/IdentityCredential` object.

<br />

| Parameters ||
|---|---|
| `credential` | `IdentityCredential`: a `https://developer.android.com/reference/android/security/identity/IdentityCredential` object. This value cannot be `null`. <br /> |

### CryptoObject

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

```
public CryptoObject (PresentationSession session)
```

Create from a `https://developer.android.com/reference/android/security/identity/PresentationSession` object.

<br />

| Parameters ||
|---|---|
| `session` | `PresentationSession`: a `https://developer.android.com/reference/android/security/identity/PresentationSession` object. This value cannot be `null`. <br /> |

### CryptoObject

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

```
public CryptoObject (Signature signature)
```

Create from a `https://developer.android.com/reference/java/security/Signature` object.

<br />

| Parameters ||
|---|---|
| `signature` | `Signature`: a `https://developer.android.com/reference/java/security/Signature` object. This value cannot be `null`. <br /> |

### CryptoObject

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

```
public CryptoObject (Cipher cipher)
```

Create from a `https://developer.android.com/reference/javax/crypto/Cipher` object.

<br />

| Parameters ||
|---|---|
| `cipher` | `Cipher`: a `https://developer.android.com/reference/javax/crypto/Cipher` object. This value cannot be `null`. <br /> |

### CryptoObject

Added in [version 36.1](https://developer.android.com/topic/libraries/support-library/revisions)

```
public CryptoObject (KeyAgreement keyAgreement)
```

Create from a `https://developer.android.com/reference/javax/crypto/KeyAgreement` object.

<br />

| Parameters ||
|---|---|
| `keyAgreement` | `KeyAgreement`: a `https://developer.android.com/reference/javax/crypto/KeyAgreement` object. This value cannot be `null`. <br /> |

### CryptoObject

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

```
public CryptoObject (Mac mac)
```

Create from a `https://developer.android.com/reference/javax/crypto/Mac` object.

<br />

| Parameters ||
|---|---|
| `mac` | `Mac`: a `https://developer.android.com/reference/javax/crypto/Mac` object. This value cannot be `null`. <br /> |

### CryptoObject

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

```
public CryptoObject (long operationHandle)
```

Create from an operation handle.

<br />

| Parameters ||
|---|---|
| `operationHandle` | `long`: the operation handle associated with this object. <br /> |

**See also:**

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

## Public methods

### getCipher

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

```
public Cipher getCipher ()
```

Get `https://developer.android.com/reference/javax/crypto/Cipher` object.

<br />

| Returns ||
|---|---|
| `https://developer.android.com/reference/javax/crypto/Cipher` | `https://developer.android.com/reference/javax/crypto/Cipher` object or null if this doesn't contain one. <br /> |

### getIdentityCredential

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

```
public IdentityCredential getIdentityCredential ()
```


**This method was deprecated
in API level 33.**   

Use `https://developer.android.com/reference/android/security/identity/PresentationSession` instead of `https://developer.android.com/reference/android/security/identity/IdentityCredential`.

Get `https://developer.android.com/reference/android/security/identity/IdentityCredential` object.

<br />

| Returns ||
|---|---|
| `https://developer.android.com/reference/android/security/identity/IdentityCredential` | `https://developer.android.com/reference/android/security/identity/IdentityCredential` object or null if this doesn't contain one. <br /> |

### getKeyAgreement

Added in [version 36.1](https://developer.android.com/topic/libraries/support-library/revisions)

```
public KeyAgreement getKeyAgreement ()
```

Get `https://developer.android.com/reference/javax/crypto/KeyAgreement` object.

<br />

| Returns ||
|---|---|
| `https://developer.android.com/reference/javax/crypto/KeyAgreement` | `https://developer.android.com/reference/javax/crypto/KeyAgreement` object or null if this doesn't contain one. <br /> |

### getMac

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

```
public Mac getMac ()
```

Get `https://developer.android.com/reference/javax/crypto/Mac` object.

<br />

| Returns ||
|---|---|
| `https://developer.android.com/reference/javax/crypto/Mac` | `https://developer.android.com/reference/javax/crypto/Mac` object or null if this doesn't contain one. <br /> |

### getOperationHandle

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

```
public long getOperationHandle ()
```

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 `https://developer.android.com/reference/android/os/Parcelable`. Hence, if the `CryptoObject` is
constructed in one process, and needs to be propagated to another process,
before calling the
`https://developer.android.com/reference/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.

<br />

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

### getPresentationSession

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

```
public PresentationSession getPresentationSession ()
```

Get `https://developer.android.com/reference/android/security/identity/PresentationSession` object.

<br />

| Returns ||
|---|---|
| `https://developer.android.com/reference/android/security/identity/PresentationSession` | `https://developer.android.com/reference/android/security/identity/PresentationSession` object or null if this doesn't contain one. <br /> |

### getSignature

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

```
public Signature getSignature ()
```

Get `https://developer.android.com/reference/java/security/Signature` object.

<br />

| Returns ||
|---|---|
| `https://developer.android.com/reference/java/security/Signature` | `https://developer.android.com/reference/java/security/Signature` object or null if this doesn't contain one. <br /> |