# Interface (SecureSession) > **NOTE** > > - The initial APIs of this module are supported since API version 10. Newly added APIs will be marked with a superscript to indicate their earliest API version. > - The initial APIs of this interface are supported since API version 12. SecureSession inherits from [Session](arkts-apis-camera-Session.md), [Flash](arkts-apis-camera-Flash.md), [AutoExposure](arkts-apis-camera-AutoExposure.md), [WhiteBalance](arkts-apis-camera-WhiteBalance.md), [Focus](arkts-apis-camera-Focus.md), and [Zoom](arkts-apis-camera-Zoom.md). It implements a secure session, which provides operations on the flash, exposure, white balance, focus, and zoom. > **NOTE** > > You can call [createSession](arkts-apis-camera-CameraManager.md#createsession11) with [SceneMode](arkts-apis-camera-e.md#scenemode11) set to **SECURE_PHOTO** to create a session in secure mode. This class is designed for applications with high security requirements, such as facial recognition systems and banking services. It must be used together with the security TA to support service scenarios where both standard preview streams and security streams are generated. > > The security TA can verify the signature of data delivered by the server, sign images, parse and assemble TLV logic, and read, create, and operate keys. It applies to image processing. ## Modules to Import ```ts import { camera } from '@kit.CameraKit'; ``` ## addSecureOutput12+ addSecureOutput(previewOutput: PreviewOutput): void Marks a [PreviewOutput](arkts-apis-camera-PreviewOutput.md) stream as secure output. **Atomic service API**: This API can be used in atomic services since API version 19. **System capability**: SystemCapability.Multimedia.Camera.Core **Parameters** | Name | Type | Mandatory| Description | | ------------- | ------------------------------- | ---- |---------------| | previewOutput | [PreviewOutput](arkts-apis-camera-PreviewOutput.md) | Yes | Preview output stream. An error code is returned if the input parameter is invalid.| **Error codes** For details about the error codes, see [Camera Error Codes](errorcode-camera.md). | ID | Error Message | | --------------- | --------------- | | 7400101 | Parameter missing or parameter type incorrect. | | 7400102 | Operation not allowed. | **Example** ```ts import { BusinessError } from '@kit.BasicServicesKit'; function addSecureOutput(session: camera.SecureSession, previewOutput: camera.PreviewOutput): void { try { session.addSecureOutput(previewOutput); } catch (error) { // If the operation fails, error.code is returned and processed. let err = error as BusinessError; console.error(`The addOutput call failed. error code: ${err.code}`); } } ``` ## on('error')12+ on(type: 'error', callback: ErrorCallback): void Subscribes to SecureSession error events. This API uses an asynchronous callback to return the result. > **NOTE** > > Currently, you cannot use **off()** to unregister the callback in the callback method of **on()**. **Atomic service API**: This API can be used in atomic services since API version 19. **System capability**: SystemCapability.Multimedia.Camera.Core **Parameters** | Name | Type | Mandatory| Description | | -------- | ------------------ | ---- | ------------------------------ | | type | string | Yes | Event type. The value is fixed at **'error'**. The event can be listened for when a session is created. This event is triggered and the error message is returned when an error occurs during the calling of a session-related API such as [beginConfig](arkts-apis-camera-Session.md#beginconfig11), [commitConfig](arkts-apis-camera-Session.md#commitconfig11-1), and [addInput](arkts-apis-camera-Session.md#addinput11).| | callback | [ErrorCallback](../apis-basic-services-kit/js-apis-base.md#errorcallback) | Yes | Callback used to return an error code defined in [CameraErrorCode](arkts-apis-camera-e.md#cameraerrorcode). | **Example** ```ts import { BusinessError } from '@kit.BasicServicesKit'; function callback(err: BusinessError): void { console.error(`Video session error code: ${err.code}`); } function registerSessionError(secureSession: camera.SecureSession): void { secureSession.on('error', callback); } ``` ## off('error')12+ off(type: 'error', callback?: ErrorCallback): void Unsubscribes from SecureSession error events. **Atomic service API**: This API can be used in atomic services since API version 19. **System capability**: SystemCapability.Multimedia.Camera.Core **Parameters** | Name | Type | Mandatory| Description | | -------- | --------------------------- | ---- | ------------------------------ | | type | string | Yes | Event type. The value is fixed at **'error'**. The event can be listened for when a session is created.| | callback | [ErrorCallback](../apis-basic-services-kit/js-apis-base.md#errorcallback)| No | Callback used to return the result. If this parameter is specified, the subscription to the specified event with the specified callback is canceled. (The callback object cannot be an anonymous function.) Otherwise, the subscriptions to the specified event with all the callbacks are canceled.| **Example** ```ts function unregisterSessionError(secureSession: camera.SecureSession): void { secureSession.off('error'); } ``` ## on('focusStateChange')12+ on(type: 'focusStateChange', callback: AsyncCallback\): void Subscribes to focus state change events. This API uses an asynchronous callback to return the result. > **NOTE** > > Currently, you cannot use **off()** to unregister the callback in the callback method of **on()**. **Atomic service API**: This API can be used in atomic services since API version 19. **System capability**: SystemCapability.Multimedia.Camera.Core **Parameters** | Name | Type | Mandatory| Description | | -------- | ---------------- | ---- | ------------------------ | | type | string | Yes | Event type. The value is fixed at **'focusStateChange'**. The event can be listened for when a session is created. This event is triggered only when the camera focus state changes in auto focus mode.| | callback | AsyncCallback\<[FocusState](arkts-apis-camera-e.md#focusstate)\> | Yes | Callback used to return the focus state change. | **Example** ```ts import { BusinessError } from '@kit.BasicServicesKit'; function callback(err: BusinessError, focusState: camera.FocusState): void { if (err !== undefined && err.code !== 0) { console.error(`Callback Error, errorCode: ${err.code}`); return; } console.info(`Focus state: ${focusState}`); } function registerFocusStateChange(secureSession: camera.SecureSession): void { secureSession.on('focusStateChange', callback); } ``` ## off('focusStateChange')12+ off(type: 'focusStateChange', callback?: AsyncCallback\): void Unsubscribes from focus state change events. **Atomic service API**: This API can be used in atomic services since API version 19. **System capability**: SystemCapability.Multimedia.Camera.Core **Parameters** | Name | Type | Mandatory| Description | | -------- | ----------------------------------------- | ---- | ------------------------ | | type | string | Yes | Event type. The value is fixed at **'focusStateChange'**. The event can be listened for when a session is created.| | callback | AsyncCallback\<[FocusState](arkts-apis-camera-e.md#focusstate)\> | No | Callback used to return the result. If this parameter is specified, the subscription to the specified event with the specified callback is canceled. (The callback object cannot be an anonymous function.) Otherwise, the subscriptions to the specified event with all the callbacks are canceled.| **Example** ```ts function unregisterFocusStateChange(secureSession: camera.SecureSession): void { secureSession.off('focusStateChange'); } ```