中国优质的IT技术网站
专业IT技术创作平台
IT职业在线教育平台
安全检测Device Security Kit的实现
微信扫码分享
import { hilog } from '@kit.PerformanceAnalysisKit'; import { safetyDetect } from '@kit.DeviceSecurityKit'; import { BusinessError} from '@kit.BasicServicesKit'; const TAG: string = '[SafetyDetectModel]'; // 请求设备完整性检测,并处理结果 let req : safetyDetect.SysIntegrityRequest = { nonce : 'imEe1PCRcjGkBCAhOCh6ImADztOZ8ygxlWRs' // 从服务器生成的随机的nonce值 }; try { hilog.info(0x0000, TAG, 'CheckSysIntegrity begin.'); const data: safetyDetect.SysIntegrityResponse = await safetyDetect.checkSysIntegrity(req); hilog.info(0x0000, TAG, 'Succeeded in checkSysIntegrity: %{public}s', data.result); } catch (err) { let e: BusinessError = err as BusinessError; hilog.error(0x0000, TAG, 'CheckSysIntegrity failed: %{public}d %{public}s', e.code, e.message); } // 请求URL检测,并处理结果 let req : safetyDetect.UrlCheckRequest = { urls : ['https://test1.com'] }; try { hilog.info(0x0000, TAG, 'CheckUrlThreat begin.'); const data: safetyDetect.UrlCheckResponse = await safetyDetect.checkUrlThreat(req); hilog.info(0x0000, TAG, 'Succeeded in checkUrlThreat: %{public}s %{public}d', data.results[0].url, data.results[0].threat); } catch (err) { let e: BusinessError = err as BusinessError; hilog.error(0x0000, TAG, 'CheckUrlThreat failed: %{public}d %{public}s', e.code, e.message); }