vue 非对称加密(RSA)
1.安装jsencrypt

npm i jsencrypt

2.新建jsencrypt.js文件

import JSEncrypt from 'jsencrypt/bin/jsencrypt.min'

// 密钥对生成 http://web.chacuo.net/netrsakeypair

const publicKey = 'MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDq0Fk7cXHnvQTgwrKftTBCWoIMFOuHgp7T/XOTRZvm8E8cLfSvKcPbMaJmF/+uzIUTwiL7IdTUX4qALkVqg8tYW4joiS6K5NWRqIPxpjSZehP1ad136o6xwjL2gIxkXQkkYMzDy5vfxsl8nFPbUxAFoiE/s+/LmI8lY4jrey6vTQIDAQAB'

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) // 对数据进行解密

}

3.在使用页面引入js文件

import { encrypt, decrypt } from '@/common/utils/jsencrypt'

4.将需要的数据进行加密即可

this.login.password = encrypt(this.login.password)
Logo

魔乐社区(Modelers.cn) 是一个中立、公益的人工智能社区,提供人工智能工具、模型、数据的托管、展示与应用协同服务,为人工智能开发及爱好者搭建开放的学习交流平台。社区通过理事会方式运作,由全产业链共同建设、共同运营、共同享有,推动国产AI生态繁荣发展。

更多推荐