Hello, I’m Anguo!

Postman is a very popular and easy to use API debugging tool, which is often used for interface debugging or testing. We can simulate sending an HTTP request by typing URL, Query String, Header, and Data directly into Postman

But what about debugging and testing “encrypted interfaces”?

CryptoJS and Pre – request Script

CryptoJS is a library of encryption algorithms implemented using JavaScript. CryptoJS supports algorithms that include:

  • Base64

  • MD5

  • And SHA SHA – 1-256

  • AES

  • Rabbit

  • MARC4

  • HMAC, HMAC-MD5, HMAC-SHA1, hMAC-SHA256

  • PBKDF2

There is a Tab “pre-request Script” in Postman that does some pre-processing before the request

For example, you can use CryptoJS to encrypt a variable, set it to a variable, and then use it on a real request

Combat the

Assume that there is a login interface whose request mode is POST, and the request body contains the username username and password, and the password is set to the request body after MD5 encryption

In this way, we only need to use CryptoJS to write JS scripts under the pre-request Script Tab to preprocess the password variables

# Pre-request Script var password = "hu123456"; Var password_encry = cryptojs.md5 ("hu123456").tostring (); Console. log(" encrypted data :"+password_encry); Set ("password_encry", password_encry); Pm.environment. Set ("password_encry", password_encry);Copy the code

There are two ways to pre-set variables: global variables and local variables

Note that if you set it to a local environment, you need to create a new environment and create a variable before it can be referenced in the JS script

Finally, replace the variable set above in the request body

The last

Postman can encrypt most of its data with CryptoJS, but it doesn’t support RSA

Here you can use another algorithm library “forgeJS” to encrypt and decrypt RSA

Project address: github.com/digitalbaza…

If you think the article is good, please like, share, leave a message, because this will be my continuous output of more high-quality articles the strongest power!