#鸿蒙通关秘籍#如何在HarmonyOS中实现AES加密的数据存取并处理不存在的键?

HarmonyOS
2024-12-02 14:51:03
浏览
收藏 0
回答 1
回答 1
按赞同
/
按时间
hm673ff115419ba

在HarmonyOS中实现AES加密的数据存储,并处理不存在的键:

console.log('-------------------本地加密存储-------------------');
JhAESPreferencesUtils.saveString('testStr', '这是测试本地加密存储的字符串');
const testStr = JhAESPreferencesUtils.getString('testStr');
console.log(`testStr : ${testStr}`);

// 处理不存在的key情况
console.log('-------------------取不存在的key----------------------');

const testStr2 = JhAESPreferencesUtils.getString('testStr222');
console.log(`testStr2原始 : ${testStr2}`);
const test = testStr2 === '' ? '1' : '2222';
console.log(`testStr2 : ${testStr2},变换后: ${test}`);

const testBool2 = JhAESPreferencesUtils.getBool('testBool222');
console.log(`testBool2 : ${testBool2}`);

const testInt2 = JhAESPreferencesUtils.getNumber('testInt222');
console.log(`testInt2: ${testInt2}`);

const testDouble2 = JhAESPreferencesUtils.getNumber('testDouble222');
console.log(`testDouble2 : ${testDouble2}`);

const testDic2 = JhAESPreferencesUtils.getModel('testDic222');
console.log(`testDic2 : ${testDic2}`);
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.
  • 19.
  • 20.
  • 21.
  • 22.
  • 23.
  • 24.

通过上面的步骤,可以在HarmonyOS中利用AES加密和解密进行安全的数据存储,同时处理键不存在的场景,确保应用的稳定性和数据的安全性。

分享
微博
QQ
微信
回复
2024-12-02 15:52:32
相关问题
如何实现文件不存在则创建文件
2886浏览 • 1回复 待解决
HarmonyOS 安装时报错依赖模块不存在
2124浏览 • 1回复 待解决
真机运行,UDID不存在
7076浏览 • 1回复 待解决
HarmonyOS 哪些情况下主窗口不存在
570浏览 • 1回复 待解决