在HarmonyOS中,可以使用HarmonyOS安全框架提供的加密解密API来实现数据加密解密。常用的加密算法包括AES、RSA等。加密解密示例代码如下:const crypto require(...
在HarmonyOS中,可以使用HarmonyOS安全框架提供的加密解密API来实现数据加密解密。常用的加密算法包括AES、RSA等。
加密解密示例代码如下:
const crypto = require('crypto');
function encryptData(data, key) {
const cipher = crypto.createCipher('aes-256-cbc', key);
let encrypted = cipher.update(data, 'utf8', 'hex');
encrypted += cipher.final('hex');
return encrypted;
}
function decryptData(encryptedData, key) {
const decipher = crypto.createDecipher('aes-256-cbc', key);
let decrypted = decipher.update(encryptedData, 'hex', 'utf8');
decrypted += decipher.final('utf8');
return decrypted;
}