> 技术文档 > 金融行业敏感数据安全防护方案:基于鸿蒙5+ 的全链路防护实践(用户信息保护案例)_金融敏感数据识别

金融行业敏感数据安全防护方案:基于鸿蒙5+ 的全链路防护实践(用户信息保护案例)_金融敏感数据识别


引言

金融行业的用户数据(如姓名、身份证号、银行卡号、交易记录)属于高敏感信息,一旦泄露可能导致用户资金损失、隐私侵犯甚至系统性金融风险。《网络安全等级保护基本要求(GB/T 22239-2019)》(等保2.0)和《个人金融信息保护技术规范》(JR/T 0171-2020)明确要求金融机构对敏感数据实施“最小化采集、加密存储、脱敏展示、权限管控”等防护措施。鸿蒙5.0及以上版本凭借​​TEE可信执行环境、原生加密API、分布式数据隔离​​等技术,为金融敏感数据防护提供了“原生安全”的技术底座。本文以某城商行手机银行App为例,结合鸿蒙5+ 能力,解析如何构建“全链路、多维度”的敏感数据安全防护体系。

一、金融敏感数据分类与防护目标

1.1 敏感数据分类

数据类型 典型场景 风险等级 防护要求 ​​身份信息​​ 姓名、身份证号、手机号、邮箱 高 最小化采集、加密存储、脱敏展示、动态授权 ​​账户信息​​ 银行卡号、账户余额、交易流水 极高 加密存储(国密SM4/ AES-256)、访问控制(RBAC)、防篡改 ​​交易信息​​ 支付密码、验证码、转账记录 极高 传输加密(TLS 1.3)、存储加密、操作日志留存(≥6个月) ​​生物信息​​ 指纹、人脸、声纹 极高 设备级隔离存储(TEE)、活体检测、使用后销毁

1.2 鸿蒙5+ 防护技术映射

鸿蒙5+ 为敏感数据防护提供了从“采集→存储→传输→展示→销毁”的全链路能力:

防护环节 鸿蒙5+ 技术支撑 ​​采集环节​abilityAccessCtrl权限管理(动态申请最小权限)、@ohos.utils.net.MaskUtils脱敏 ​​存储环节​​ TEE可信执行环境(安全存储密钥)、distributedData分布式加密存储(分域隔离) ​​传输环节​​ TLS 1.3内置支持(http模块自动升级)、@ohos.net.http安全通道 ​​展示环节​MaskUtils动态脱敏(姓名→张*、身份证→310101​​​​​​​​1234)、隐私弹窗确认 ​​销毁环节​distributedData数据过期策略(自动清理超期数据)、tee安全擦除(密钥销毁)

二、实战案例:手机银行App敏感数据防护(鸿蒙5+ 代码实现)

2.1 场景需求

用户使用手机银行App时,需完成以下敏感操作,同时满足防护要求:

  1. 注册/登录(采集手机号、密码,传输至后端);
  2. 账户信息查询(展示姓名、银行卡号,脱敏处理);
  3. 转账交易(输入支付密码,加密传输至后端);
  4. 生物识别(指纹登录,设备级存储密钥)。

2.2 核心模块实现(代码示例)

2.2.1 敏感数据采集:最小化权限+动态申请

​需求​​:仅采集必要信息(如手机号、密码),动态申请权限,避免过度索权。

​鸿蒙5+ 实现​​:使用abilityAccessCtrl动态申请权限,结合@ohos.utils.net.MaskUtils预脱敏。

// 注册模块(RegisterAbility.ts)import abilityAccessCtrl from \'@ohos.abilityAccessCtrl\';import promptAction from \'@ohos.promptAction\';import maskUtils from \'@ohos.utils.net.maskUtils\';export default class RegisterAbility extends UIAbility { async onStart(want, launchParam) { // 1. 动态申请手机号权限(最小化采集) const phonePermission = \'ohos.permission.READ_PHONE_STATE\'; const authResult = await abilityAccessCtrl.checkPermission(phonePermission); if (authResult !== abilityAccessCtrl.PermissionState.GRANTED) { const grantResult = await promptAction.requestPermissionsFromUser({ permissions: [phonePermission], reason: \'需要获取手机号完成注册\' }); if (grantResult !== promptAction.ResultCode.PERMISSION_GRANTED) { promptAction.showToast({ message: \'请授权手机号权限以完成注册\' }); return; } } // 2. 预脱敏手机号(用户输入时实时脱敏) this.phoneInputController = new TextInputController({ onChange: (value) => { this.setState({ phone: maskUtils.mask(value, { type: maskUtils.MaskType.PHONE }) }); } }); }}
2.2.2 敏感数据存储:TEE加密+分布式分域

​需求​​:用户密码、银行卡号等敏感信息需加密存储,防止本地窃取或越权访问。

​鸿蒙5+ 实现​​:使用TEE存储加密密钥,distributedData按用户分域加密存储。

// 安全存储服务(SecureStorageService.ts)import tee from \'@ohos.security.tee\';import distributedData from \'@ohos.data.distributedData\';import crypto from \'@ohos.security.crypto\';export class SecureStorageService { private static teeContext: tee.TEEContext | null = null; private static storageDomain = \'user_secure_data\'; // 分域存储键 /** * 初始化TEE上下文(首次启动时调用) */ async initTee() { try { this.teeContext = await tee.TEEContext.create(); // 生成并存储AES密钥(仅存储密钥哈希,密钥本身存于TEE) const key = crypto.generateKey({ name: \'AES-GCM\', length: 256 }); const keyHash = await crypto.digest(\'SHA-256\', key.export()); await this.teeContext.setSecretData(\'aes_key_hash\', keyHash); } catch (err) { console.error(\'TEE初始化失败:\', err); } } /** * 加密存储敏感数据(如密码) * @param userId 用户ID * @param data 明文数据(如密码) */ async encryptAndStore(userId: string, data: string) { try { // 1. 从TEE获取密钥哈希(实际需通过哈希获取密钥) const keyHash = await this.teeContext?.getSecretData(\'aes_key_hash\'); if (!keyHash) throw new Error(\'密钥未初始化\'); // 2. 使用AES-256-GCM加密数据 const key = await crypto.importKey(\'raw\', new Uint8Array(32), { name: \'AES-GCM\' }, false, [\'encrypt\']); const iv = crypto.getRandomValues(new Uint8Array(12)); const encrypted = crypto.encrypt({ name: \'AES-GCM\', iv }, key, new TextEncoder().encode(data)); // 3. 存储加密数据至分布式数据库(按用户分域) const ddb = await distributedData.getDistributedDataObject(); const storageKey = `${this.storageDomain}_${userId}_password`; await ddb.put(storageKey, { iv: Array.from(iv), ciphertext: Array.from(new Uint8Array(encrypted)) }); } catch (err) { console.error(\'数据加密存储失败:\', err); } } /** * 解密获取敏感数据(如登录验证) * @param userId 用户ID * @returns 明文数据(如密码) */ async decryptAndGet(userId: string): Promise { try { // 1. 从分布式数据库获取加密数据 const ddb = await distributedData.getDistributedDataObject(); const storageKey = `${this.storageDomain}_${userId}_password`; const encryptedData = await ddb.get(storageKey); if (!encryptedData) return null; // 2. 从TEE获取密钥并解密 const keyHash = await this.teeContext?.getSecretData(\'aes_key_hash\'); const key = await crypto.importKey(\'raw\', new Uint8Array(32), { name: \'AES-GCM\' }, false, [\'decrypt\']); const decrypted = crypto.decrypt( { name: \'AES-GCM\', iv: new Uint8Array(encryptedData.iv) }, key, new Uint8Array(encryptedData.ciphertext) ); return new TextDecoder().decode(decrypted); } catch (err) { console.error(\'数据解密失败:\', err); return null; } }}
2.2.3 敏感数据传输:TLS 1.3+双向认证

​需求​​:用户登录、转账等操作需通过安全通道传输,防止中间人攻击。

​鸿蒙5+ 实现​​:http模块自动升级至TLS 1.3,结合双向证书认证。

// 网络请求服务(SecureHttpService.ts)import http from \'@ohos.net.http\';import promptAction from \'@ohos.promptAction\';export class SecureHttpService { private static baseUrl = \'https://api.bank.com\'; // 后端HTTPS地址 /** * 发送安全请求(自动TLS 1.3 + 双向认证) * @param url 请求路径 * @param method 请求方法 * @param data 请求体 */ async request(url: string, method: string, data?: any) { try { const httpRequest = http.createHttp(); // 配置TLS 1.3(鸿蒙5+ 默认启用) const sslConfig = { version: http.SSLVersion.TLS_1_3, // 双向认证(可选,根据业务需求开启) // clientCertificate: await this.getClientCertificate() }; httpRequest.setSSLConfig(sslConfig); // 发送请求 const response = await httpRequest.request( `${this.baseUrl}${url}`, { method: http.RequestMethod[method.toUpperCase()], extraData: data ? JSON.stringify(data) : undefined, header: { \'Content-Type\': \'application/json\' } } ); if (response.responseCode !== 200) { throw new Error(`请求失败:${response.responseCode}`); } return response.result; } catch (err) { console.error(\'安全请求失败:\', err); promptAction.showToast({ message: \'网络请求失败,请检查网络\' }); return null; } }}
2.2.4 敏感数据展示:动态脱敏+隐私弹窗

​需求​​:账户信息、交易记录等需脱敏展示,且用户首次查看时需确认授权。

​鸿蒙5+ 实现​​:MaskUtils动态脱敏,结合permissionAccessCtrl请求展示权限。

// 账户信息模块(AccountInfoAbility.ts)import abilityAccessCtrl from \'@ohos.abilityAccessCtrl\';import maskUtils from \'@ohos.utils.net.maskUtils\';import promptAction from \'@ohos.promptAction\';export default class AccountInfoAbility extends UIAbility { private accountData: { name: string, cardNo: string, balance: number } | null = null; async onStart(want, launchParam) { // 1. 请求账户信息展示权限(首次查看时) const displayPermission = \'ohos.permission.DISPLAY_ACCOUNT_INFO\'; const authResult = await abilityAccessCtrl.checkPermission(displayPermission); if (authResult !== abilityAccessCtrl.PermissionState.GRANTED) { const grantResult = await promptAction.requestPermissionsFromUser({ permissions: [displayPermission], reason: \'需要展示账户信息以完成操作\' }); if (grantResult !== promptAction.ResultCode.PERMISSION_GRANTED) { promptAction.showToast({ message: \'请授权账户信息展示权限\' }); return; } } // 2. 加载账户数据(从SecureStorageService获取解密后数据) this.accountData = await this.loadAccountData(); this.updateUI(); } /** * 更新UI(脱敏展示) */ private updateUI() { if (!this.accountData) return; const maskedName = maskUtils.mask(this.accountData.name, { type: maskUtils.MaskType.NAME }); // 张* const maskedCard = maskUtils.mask(this.accountData.cardNo, { type: maskUtils.MaskType.BANK_CARD }); // 6228****1234 // 渲染到页面 }}
2.2.5 生物识别:设备级隔离+活体检测

​需求​​:指纹/人脸登录需仅存储设备级密钥,防止跨设备窃取。

​鸿蒙5+ 实现​​:使用@ohos.biometrics接口,结合TEE存储生物特征模板。

// 生物识别服务(BiometricService.ts)import biometrics from \'@ohos.biometrics\';import tee from \'@ohos.security.tee\';export class BiometricService { private static teeContext: tee.TEEContext | null = null; async init() { this.teeContext = await tee.TEEContext.create(); // 存储生物特征模板(加密后) const template = await this.captureFingerprint(); // 捕获指纹模板(设备级) const encryptedTemplate = await this.encryptTemplate(template); await this.teeContext.setSecretData(\'fingerprint_template\', encryptedTemplate); } /** * 捕获指纹模板(设备级存储,不上传) */ private async captureFingerprint(): Promise { // 调用鸿蒙生物识别API(示例) const result = await biometrics.startFingerprintRecognition({ challenge: new Uint8Array(16), // 随机挑战值防重放 authType: biometrics.AuthType.FINGERPRINT }); return result.template; // 设备级生成的模板(不离开设备) } /** * 加密生物特征模板(AES-256-GCM) */ private async encryptTemplate(template: Uint8Array): Promise { const key = await crypto.generateKey({ name: \'AES-GCM\', length: 256 }); const iv = crypto.getRandomValues(new Uint8Array(12)); return crypto.encrypt({ name: \'AES-GCM\', iv }, key, template); }}

三、防护效果验证与合规性

3.1 验证方法

验证项 测试工具/方法 预期结果 数据最小化采集 使用hdc shell logcat监控权限申请日志,检查是否仅申请必要权限 仅申请手机号、存储等最小权限 加密存储验证 使用hdc shell ls /data查看应用私有目录,确认数据为密文(非明文) 私有目录文件内容为乱码 传输加密验证 使用抓包工具(如Wireshark)拦截网络请求,检查TLS版本和证书 仅TLS 1.3连接,证书链完整 脱敏展示验证 模拟用户查看账户信息,检查姓名、银行卡号是否脱敏(如张*、6228​​​​1234) 敏感字段显示为脱敏后格式 权限管控验证 移除用户存储权限,验证应用是否无法保存敏感数据 应用提示“权限不足,无法保存”

3.2 合规性总结

本方案严格遵循等保2.0和金科监要求:

  • ​数据最小化​​:仅采集必要信息(手机号、密码),动态申请权限;
  • ​加密存储​​:TEE+AES-256-GCM双重加密,分布式分域隔离;
  • ​传输安全​​:TLS 1.3+双向认证,防止中间人攻击;
  • ​脱敏展示​​:动态脱敏算法(MaskUtils),隐私弹窗授权;
  • ​可追溯性​​:操作日志留存(结合eventHub),满足审计要求。

四、总结与最佳实践

4.1 总结

鸿蒙5+ 凭借​​TEE可信执行环境、原生加密API、分布式数据隔离​​等技术,为金融敏感数据防护提供了“开箱即用”的解决方案。通过最小化采集、加密存储、脱敏展示、权限管控等全链路措施,可有效防范数据泄露风险,满足监管合规要求。

4.2 最佳实践

  1. ​最小化权限申请​​:仅申请必要权限(如手机号、存储),避免过度索权;
  2. ​分层加密策略​​:敏感数据“本地TEE加密+分布式存储加密”双重防护;
  3. ​动态脱敏展示​​:结合业务场景动态调整脱敏规则(如客服查看部分信息);
  4. ​权限生命周期管理​​:敏感权限“用时申请,用完回收”,避免长期持有;
  5. ​定期安全审计​​:使用鸿蒙App Profiler监控权限使用、数据流向,及时修复漏洞。