uniapp vue3版本引用 jsencrypt加密库报错:“default“ is not exported by……

个人产生这个异常的原因:将历史项目(vue2)的jsencrypt文件复制到新项目(vue3)里直接引用报错。存在兼容问题,需要重新安装vue3版本的jsencrypt

安装依赖

复制代码
npm install jsencrypt

页面引入

js 复制代码
import { JSEncrypt } from 'jsencrypt'

简单封装

js 复制代码
import {
	JSEncrypt
} from 'jsencrypt'
// 密钥对生成 http://web.chacuo.net/netrsakeypair
const publicKey ='你的公钥'
const privateKey = '你的私钥'

// 加密
export function encrypt(txt) {
	const encryptor = new JSEncrypt()
	encryptor.setPublicKey(publicKey) // 设置公钥
	return encryptor.encrypt(txt) // 对数据进行加密
}

// 解密
export function decrypt(txt) {
	const encryptor = new JSEncrypt()
	encryptor.setPrivateKey(privateKey) // 设置私钥
	return encryptor.decrypt(txt) // 对数据进行解密
}

具体使用

js 复制代码
<script>
	import {
		encrypt
	} from '@/utils/rsa/jsencrypt-vue3.js'
	export default {
		data() {
			return {
			}
		},
		methods: {
			startLogin() {		
			    var param = {
					username: 'xxxxx',
					
					// 调用加密方法,完成密码的rsa加密
					password: encrypt('xxxxxx')
				}
			}
		}
	}
</script>

参考资料

uniapp vue3版本 Android 引用 jsencrypt加密库 报错问题 "default" is not exported by,解决方法
前端VUE3使用RSA加密向后端传输密码
微信小程序使用npm方式增加jsencrypt rsa加密验证

相关推荐
半路_出家ren1 分钟前
Python操作MySQL(详细版)
运维·开发语言·数据库·python·mysql·网络安全·wireshark
共享家95271 分钟前
MYSQL-内外连接
开发语言·数据库·mysql
ppo_wu4 分钟前
介绍下CompletableFuture的用法
java·开发语言
吴佳浩 Alben4 分钟前
Python入门指南(七) - YOLO检测API进阶实战
开发语言·python·yolo
沐知全栈开发8 小时前
HTML5 浏览器支持
开发语言
wasp5208 小时前
AgentScope Java 核心架构深度解析
java·开发语言·人工智能·架构·agentscope
WHOVENLY8 小时前
【javaScript】- 笔试题合集(长期更新,建议收藏,目前已更新至31题)
开发语言·前端·javascript
慌糖8 小时前
流-为序列化解释
开发语言
指尖跳动的光8 小时前
将多次提交合并成一次提交
前端·javascript
若梦plus9 小时前
JS之类型化数组
前端·javascript