中国优质的IT技术网站
专业IT技术创作平台
IT职业在线教育平台
如何设置键值型数据库的安全级别?
微信扫码分享
import distributedKVStore from '@ohos.data.distributedKVStore'; import { BusinessError } from '@ohos.base'; let kvManager: distributedKVStore.KVManager; let kvStore: distributedKVStore.SingleKVStore; let context = getContext(this); const kvManagerConfig: distributedKVStore.KVManagerConfig = { context: context, bundleName: 'com.example.datamanagertest' } try { kvManager = distributedKVStore.createKVManager(kvManagerConfig); console.info('Succeeded in creating KVManager.'); try { const options: distributedKVStore.Options = { createIfMissing: true, encrypt: true, backup: false, autoSync: false, kvStoreType: distributedKVStore.KVStoreType.SINGLE_VERSION, securityLevel: distributedKVStore.SecurityLevel.S1//安全等级为S1 }; kvManager.getKVStore<distributedKVStore.SingleKVStore>('storeId', options, (err, store: distributedKVStore.SingleKVStore) => { if (err) { console.error(`Failed to get KVStore. Code:${err.code},message:${err.message}`); return; } console.info('Succeeded in getting KVStore.'); kvStore = store; }); } catch (e) { let error = e as BusinessError; console.error(`An unexpected error occurred. Code:${error.code},message:${error.message}`); } } catch (e) { let error = e as BusinessError; console.error(`Failed to create KVManager. Code:${error.code},message:${error.message}`); }