1# Setting the Security Level of a Distributed File 2 3The 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). 4 5## Available APIs 6 7For details about the APIs, see [ohos.file.securityLabel](../reference/apis-core-file-kit/js-apis-file-securityLabel.md). 8 9**Table 1** Security level APIs 10 11| API| Description| Category| Synchronous Programming| Asynchronous Programming| 12| -------- | -------- | -------- | -------- | -------- | 13| setSecurityLabel | Sets a security level for a file.| Method| Supported| Supported| 14| getSecurityLabel | Obtains the security level of a file.| Method| Supported| Supported| 15 16> **NOTE** 17> 18> - In distributed networking, a device can view the files that have a higher security level but cannot access them. 19> 20> - The default security level of the distributed file system data is S3. Applications can set the security level of files. 21 22## Development Example 23 24Obtain 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). 25 26 27```ts 28import { securityLabel } from '@kit.CoreFileKit'; 29import { BusinessError } from '@kit.BasicServicesKit'; 30import { common } from '@kit.AbilityKit'; 31import { fileIo as fs } from '@kit.CoreFileKit'; 32 33// Obtain the sandbox path of the file. 34let context = getContext(this) as common.UIAbilityContext; // Obtain UIAbilityContext. 35let pathDir = context.filesDir; 36let filePath = pathDir + '/test.txt'; 37 38// Open the file. 39let file = fs.openSync(filePath, fs.OpenMode.READ_WRITE | fs.OpenMode.CREATE); 40// Set the data level of the file to S0. 41securityLabel.setSecurityLabel(filePath, 's0').then(() => { 42 console.info('Succeeded in setSecurityLabeling.'); 43 fs.closeSync(file); 44}).catch((err: BusinessError) => { 45 console.error(`Failed to setSecurityLabel. Code: ${err.code}, message: ${err.message}`); 46}); 47``` 48