jmeter调用js加密用户密码

jmeter调用js加密用户密码_第1张图片


all.js放到jmeter的bin目录下

原始代码:

load("all.js");
//获取公共modulus
var modulus = vars.get("modulus");
log.info(modulus);
//获取公共modulus
var exponent = vars.get("exponent");
log.info(exponent);
//要加密的密码
var adminpassword = vars.get("admin_password");
log.info(adminpassword);
function RSA(){
    var rsa = new RSAKey();
    rsa.setPublic(modulus, exponent);
    var enpassword = rsa.encrypt(adminpassword);
    return enpassword;
}
var password = RSA();
log.info(password);
//将加密的密码存入enadmin_password
vars.put("enadmin_password",password);

调试

jmeter调用js加密用户密码_第2张图片


遇到的问题:

调试时总是报 navigator 未定义,这是因为navigator是windows浏览器的变量,如果不用windows浏览器变量,这个值报错,相关代码注释掉就好啦

//if (j_lm && (navigator.appName == "Microsoft Internet Explorer")) {
 //BigInteger.prototype.am = am2;
  //dbits = 30;
//} else if (j_lm && (navigator.appName != "Netscape")) {
  //BigInteger.prototype.am = am1;
  //dbits = 26;
//} else { // Mozilla/Netscape seems to prefer am3
  BigInteger.prototype.am = am3;
  dbits = 28;
//}


if (rng_pool == null) {
  rng_pool = [];
  rng_pptr = 0;
  var t;
  //if (window.crypto && window.crypto.getRandomValues) {
    // Use webcrypto if available
    //var ua = new Uint8Array(32);
    //window.crypto.getRandomValues(ua);
    //for (t = 0; t < 32; ++t)
      //rng_pool[rng_pptr++] = ua[t];
  //}
  //if (navigator.appName == "Netscape" && navigator.appVersion < "5" && window.crypto) {
    // Extract entropy (256 bits) from NS4 RNG if available
    //var z = window.crypto.random(32);
    //for (t = 0; t < z.length; ++t)
      //rng_pool[rng_pptr++] = z.charCodeAt(t) & 255;
  //}
  //while (rng_pptr < rng_psize) { // extract some randomness from Math.random()
    //t = Math.floor(65536 * Math.random());
    //rng_pool[rng_pptr++] = t >>> 8;
    //rng_pool[rng_pptr++] = t & 255;
  //}
  //rng_pptr = 0;
  //rng_seed_time();
  //rng_seed_int(window.screenX);
  //rng_seed_int(window.screenY);
}

jmeter调用js加密用户密码_第3张图片jmeter调用js加密用户密码_第4张图片




你可能感兴趣的:(测试相关)