御剑飞天
御剑飞天
  • 发布:2025-04-18 10:30
  • 更新:2025-04-18 10:49
  • 阅读:23

我想将一些敏感的数据存储在云数据库,要如何对其进行加密存储及如果在前端解密使用

分类:uniCloud

我想将一些敏感的数据存储在云数据库,要如何对其进行加密存储及如果在前端解密使用

2025-04-18 10:30 负责人:无 分享
已邀请:

最佳回复

DCloud_uniCloud_VK

DCloud_uniCloud_VK

加密和解密都得在云函数里做,下面的加密和解密的代码示例

const crypto = require('crypto');  

// 密钥  
const key = "5d44a032652974c3e53644945a95b126"; // 固定32位  

// 待加密的文本  
const text = '我是待加密的信息';  
console.log('加密前的原文:', text);  

// 加密  
const cipher = crypto.createCipheriv('aes-256-ecb', key, '');  
let encrypted = cipher.update(text, 'utf8', 'base64');  
encrypted += cipher.final('base64');  
console.log('加密后的密文:', encrypted);  

// 解密  
const decipher = crypto.createDecipheriv('aes-256-ecb', key, '');  
let decrypted = decipher.update(encrypted, 'base64', 'utf8');  
decrypted += decipher.final('utf8');  
console.log('解密后的明文:', decrypted);  

要回复问题请先登录注册