1. 程式人生 > >jmeter呼叫js加密使用者密碼

jmeter呼叫js加密使用者密碼

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);

除錯


遇到的問題:

除錯時總是報 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);
}