1e41f4b71Sopenharmony_ci# Setting the Security Level of a Distributed File
2e41f4b71Sopenharmony_ci
3e41f4b71Sopenharmony_ciThe security capabilities vary with devices. For example, small embedded devices provide fewer security capabilities than tablets. The security requirements also vary with data. For example, personal health information and bank card information are not expected to be accessed by devices of lower security levels. OpenHarmony provides a complete set of data and device classification standards and supports customization of data transfer policies for different devices. For details, see [Access Control by Device and Data Level](../database/access-control-by-device-and-data-level.md).
4e41f4b71Sopenharmony_ci
5e41f4b71Sopenharmony_ci## Available APIs
6e41f4b71Sopenharmony_ci
7e41f4b71Sopenharmony_ciFor details about the APIs, see [ohos.file.securityLabel](../reference/apis-core-file-kit/js-apis-file-securityLabel.md).
8e41f4b71Sopenharmony_ci
9e41f4b71Sopenharmony_ci**Table 1** Security level APIs
10e41f4b71Sopenharmony_ci
11e41f4b71Sopenharmony_ci| API| Description| Category| Synchronous Programming| Asynchronous Programming| 
12e41f4b71Sopenharmony_ci| -------- | -------- | -------- | -------- | -------- |
13e41f4b71Sopenharmony_ci| setSecurityLabel | Sets a security level for a file.| Method| Supported| Supported| 
14e41f4b71Sopenharmony_ci| getSecurityLabel | Obtains the security level of a file.| Method| Supported| Supported| 
15e41f4b71Sopenharmony_ci
16e41f4b71Sopenharmony_ci> **NOTE**
17e41f4b71Sopenharmony_ci>
18e41f4b71Sopenharmony_ci> - In distributed networking, a device can view the files that have a higher security level but cannot access them.
19e41f4b71Sopenharmony_ci>
20e41f4b71Sopenharmony_ci> - The default security level of the distributed file system data is S3. Applications can set the security level of files.
21e41f4b71Sopenharmony_ci
22e41f4b71Sopenharmony_ci## Development Example
23e41f4b71Sopenharmony_ci
24e41f4b71Sopenharmony_ciObtain the sandbox path of a file and set the data security level. For details about how to obtain the context, see [Obtaining the Context of UIAbility](../application-models/uiability-usage.md#obtaining-the-context-of-uiability).
25e41f4b71Sopenharmony_ci
26e41f4b71Sopenharmony_ci  
27e41f4b71Sopenharmony_ci```ts
28e41f4b71Sopenharmony_ciimport { securityLabel } from '@kit.CoreFileKit';
29e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit';
30e41f4b71Sopenharmony_ciimport { common } from '@kit.AbilityKit';
31e41f4b71Sopenharmony_ciimport { fileIo as fs } from '@kit.CoreFileKit';
32e41f4b71Sopenharmony_ci
33e41f4b71Sopenharmony_ci// Obtain the sandbox path of the file.
34e41f4b71Sopenharmony_cilet context = getContext(this) as common.UIAbilityContext; // Obtain UIAbilityContext.
35e41f4b71Sopenharmony_cilet pathDir = context.filesDir;
36e41f4b71Sopenharmony_cilet filePath = pathDir + '/test.txt';
37e41f4b71Sopenharmony_ci
38e41f4b71Sopenharmony_ci// Open the file.
39e41f4b71Sopenharmony_cilet file = fs.openSync(filePath, fs.OpenMode.READ_WRITE | fs.OpenMode.CREATE);
40e41f4b71Sopenharmony_ci// Set the data level of the file to S0.
41e41f4b71Sopenharmony_cisecurityLabel.setSecurityLabel(filePath, 's0').then(() => {
42e41f4b71Sopenharmony_ci  console.info('Succeeded in setSecurityLabeling.');
43e41f4b71Sopenharmony_ci  fs.closeSync(file);
44e41f4b71Sopenharmony_ci}).catch((err: BusinessError) => {
45e41f4b71Sopenharmony_ci  console.error(`Failed to setSecurityLabel. Code: ${err.code}, message: ${err.message}`);
46e41f4b71Sopenharmony_ci});
47e41f4b71Sopenharmony_ci```
48