uniapp中如何使用jsencrypt加密

1,222 阅读1分钟

uniapp中如何引入jsencrypt做加密

1、下载jsencrypt文件放在合适位置(common或者static)

2、在main.js中引入

`import JSEncrypt from '@/static/js/jsencrypt.js'

Vue.prototype.$encryptByPublicKey=function(content) {

let encrypt = new JSEncrypt();

encrypt.setPublicKey("xxx")

return encrypt.encrypt(content); }`

3、在具体页面使用

如:this.$encryptByPublicKey(this.loginForm.password)

注意:jsencrypt.js在uniapp或者其他移动设备中有少许不一样;它们环境中没有window对象因此要予以替换

附jsencrypt.js代码

`