May I ask axios, how to encrypt the api interface at the front end?

ask axios, how to encrypt the api interface at the front end

Mar.30,2022

just encrypt the request parameters.. Is it difficult


parameters can be encrypted

param2String = data => {
   if (typeof data === 'string') {
       return data;
   }
  let ret = '';
  for (let it in data) {
      let val = data[it];
      if (typeof val === 'object' && (!(val instanceof Array) || (val.length > 0 && (typeof val[0] === 'object')))) {
         val = JSON.stringify(val);
      }
      ret += it + '=' + encodeURIComponent(val) + '&';
  }
  if (ret.length > 0) {
      ret = ret.substring(0, ret.length - 1);
  }
 return ret;
};

and then decode it in the background


you can use the js-md5 library to encrypt parameters.


General processing can be done using md5 or RAS encryption

Menu