RSA非对称加密


import JSEncryptLong from 'encryptlong'
 
Vue.config.productionTip = false
 
Vue.prototype.$getRsaCode = function (str) {
 
  let pubKey = 'MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCIOW25e95q31RrHUiL/RMYkbmn2C0O/RNMwD4sGfFRa7tj+wrFqF17IPvRcN5hJKFDxElgjJuQKZ+3v80VLhYQge2He3yskCwVqaiwfNdT5ThROqGBwnowKXpB6enxgm8D8my8bKrh9jkTNFFEIEaDtV0tMB0D10k2WK/iLJYLfwIDAQAB'
 
  let encryptStr = new JSEncryptLong()
 
  encryptStr.setPublicKey(pubKey) // 设置 加密公钥
 
  let data = encryptStr.encryptLong(str) // 进行加密
 
  return data
 
}
var JSONString = '{"username":"' + this.username + '","password":"' 
+ this.password + '","grant_type":"password","client_id":"hello","client_secret":"123456","login_type":"WEB"}'

下发成功后把token加到请求头

 this.$axios.defaults.headers.common['Authorization'] = data.tokenHead + encodeURIComponent(data.token)

这样就成功了,以后每次请求后端都会校验请求头

生成公钥跟私钥的网站
http://web.chacuo.net/netrsakeypair

你可能感兴趣的:(RSA非对称加密)