How to import Cryptojs in Jmeter

一世执手 提交于 2020-01-07 02:48:08

问题


In one of the http request we have to send encrypted value.

The encryption is done by the CryptoJs javascript libraries and Algorithm used is AES256.

I am new to Jmeter can anyone let me know how to import the CryptoJs libraries and how to use the function of same to encrypt and decrypt the same.


回答1:


I recall answering something similar already, see How to load external js library in Jmeter?

Quoting myself:

Use Rhino load() method like:

   load("crypto.js")

Given the guy wasn't able to use the instruction here is a little bit extended version:

  1. Download the required version of CryptoJS from the releases page and unpack it somewhere
  2. Using load method provide full path to crypto-js.js file like:

    /tmp/crypto-js-3.1.7/crypto-js.js
    
  3. Access methods like

    • CryptoJS.SHA256(...)
    • CryptoJS.AES(...)
    • etc.

Demo:

If the values are static and you don't have a lot of them a better idea could be storing them into a file and accessing via i.e. CSV Data Set Config




回答2:


JMeter is not a browser.

Javascript is run through Rhino or Nashorn.

So your best option is to look at CryptoJS code and either:

  • use it in a JSR223-Preprocessor using Javascript language

  • Translate code to Groovy/Java using JSR223-Preprocessor + groovy

See:

  • Java 256-bit AES Password-Based Encryption


来源:https://stackoverflow.com/questions/40015014/how-to-import-cryptojs-in-jmeter

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!