uni-app AES 加密

uni-app 官网没有 加密 API

我们 可以 安装 crypto-js

复制代码
npm install crypto-js

他会保存到项目中 node_modules

复制代码
import CryptoJS from '../node_modules/crypto-js' //引用AES源码js
const keyCode = '012345678' //密钥
const ivCode = '012345678' //偏移量

const key = CryptoJS.enc.Utf8.parse(keyCode);
const iv = CryptoJS.enc.Utf8.parse(ivCode);
const utils = {
	encodeAES(text) {
		const encrypted = CryptoJS.AES.encrypt(text, key, {
			iv: iv,
			mode: CryptoJS.mode.CBC,
			padding: CryptoJS.pad.Pkcs7
		});

		let enText = encrypted.toString()
		if (enText == '') {
			enText = text
		}
		console.log('enText: ', enText);
		return enText;
	},
	decodeAES(enText) {
		const decrypt = CryptoJS.AES.decrypt(enText, key, {
			iv: iv,
			mode: CryptoJS.mode.CBC,
			padding: CryptoJS.pad.Pkcs7
		})

		const decryptedStr = decrypt.toString(CryptoJS.enc.Utf8)
		let text = decryptedStr.toString()
		if (text == '') {
			text = enText
		}
		console.log('text: ', text);
		return text
	},
}

export default utils
相关推荐
Wellijohn2 小时前
一个 Android 老兵的十年开源路:从 167 star 的滑动控件,到本地优先的 AI Agent
android·人工智能·开源
好的佩奇7 小时前
Dart 之元数据与注解
android·flutter·dart
inksci7 小时前
用飞帆做了个小网页
前端·javascript·css·html
zhensherlock8 小时前
Protocol Launcher 系列:CodeHub 移动端 GitHub 协作利器
前端·javascript·typescript·node.js·自动化·github·js
三少爷的鞋8 小时前
很多开发者把物理上的分层,当成了架构
android
FungLeo10 小时前
FengCMS · PHP+MySQL 升级实录 · MySQL DDL不能回滚:模型字段结构操作的失败续做
android·mysql·php·工程实践·fengcms
雨白10 小时前
Android 建造者模式实战:从 AlertDialog 源码到 TopBar 的两种实现
android
多加点辣也没关系11 小时前
JavaScript|第40章:JavaScript 工程化实践
开发语言·javascript·ecmascript
_祝你今天愉快13 小时前
Android 高级绘制:[五] 贝塞尔曲线与计算规则
android
彩虹暴龙兽13 小时前
JavaScript 预编译机制与执行上下文构建分析
javascript