vue-cli public key encryption

Define the public key in data

publicKey:''

use

Install npm install jsencrypt

Introduce  import {JSEncrypt} from 'jsencrypt'

Use (if the method is defined, it is prone to the problem that the background interface returns the public key asynchronously, so that no assignment is successful)

(For reference only, the encryption parameters can be changed according to the needs)

// 公钥加密
				// this.time = Date.parse(new Date()); //时间戳
				// let {
				// 	data: res2
				// } = await this.axios({
				// 	method: 'get',
				// 	url: conf.api_base_url + '/asymmetricCrypto/getPublicKey?t=' + this.time,
				// 	// headers: {
				// 	// 	'content-type': 'multipart/form-data'
				// 	// },
				// })
				// console.log("后台获取公钥响应")
				// console.log(res2);
				// this.publicKey = res2;
				// let encrypt = new JSEncrypt();
				// // 设置公钥
				// let encryptStr = new JSEncrypt();
				// encryptStr.setPublicKey(this.publicKey); // 设置 加密公钥
				// this.registerParams.password= encryptStr.encrypt(this.registerParams.password); // 进行加密
				// console.log("加密为"+this.registerParams.password)	
				// this.registerParams.password = this.getEncrypt(this.registerParams.password); //公钥加密
				// this.phone = this.contactPhone;  //写死手机和联系手机一致  
				// console.log("加密密码为:");
				// console.log(this.registerParams.password);

Guess you like

Origin blog.csdn.net/enhenglhm/article/details/122558276