Location>code7788 >text

Jmeter SHA512 interface encryption test

Popularity:989 ℃/2024-08-06 18:09:49

Preface: Recently, I encountered some test interfaces must be passed after SHA512 encrypted sign signature, and the signature has a time limit of 1 hour, that is, the signature is not set in stone more than 1 hour will expire, which leads to the test process will have to frequently manually update the signature. In fact, Jmeter is to provide a function to automatically convert the following details

SHA512 encryption, you can go online to search SHA512 online conversion

 

1, known, the interface request must pass four parameters tenantCode, timestamp, nonce, sign

{
    "tenantCode":"",
    "timestamp":"",
    "nonce":"",
    "sign":""
}

Where sign is a signature encrypted with SHA512, the calculation rule is as follows [where appSecret=573e182924f8d40fd4566989ace22729e8d4a1cb]:

  • Splice together a string in order tenantCode${tenantCode}nonce${nonce}timestamp${timestamp}${appSecret}
  • SHA512 encrypts the string
  • Uppercase the encrypted string to get sign

 

2. Examples:

{
    "tenantCode":"jkdsa",
    "timestamp":"1722938712",
    "nonce":"3754",
    "sign":"5F61CFD4AE4FD799C644659F14B81ABF510941F6EDA4C16349018E6A3872281A7794A43A3CF3E7734B7AD1E553ADA562AAA5DBA90188CF22A8781CE8BAF7C158"
}

Here's how the sign is calculated manually based on the rules

  • The splice string is: tenantCodejkdsanonce3754timestamp1722938712573e182924f8d40fd4566989ace22729e8d4a1cb
  • SHA512 encryption is: tenantCodejkdsanonce3754timestamp1722938712573e182924f8d40fd4566989ace22729e8d4a1cb
  • Converted to uppercase as: 5f61cfd4ae4fd799c644659f14b81abf510941f6eda4c16349018e6a3872281a7794a43a3cf3e7734b7ad1e553ada562aaa5dba90188cf22a8781ce8baf7c158

 

3, due to the sign signature is a 1-hour time limit, test the interface process in order to reduce the manual frequently to update the signature, I used the Jmeter function to automatically convert, with theV-function (math.)(for executing variable names, nested functions),digest function(for encryption),changeCase function(for character case conversion)

 

 

{
    "tenantCode":"${tenantCode}",
    "timestamp":"${timestamp}",
    "nonce":"${nonce}",
    "sign":"${__changeCase(${__digest(SHA-512,${__V(tenantCode${tenantCode}nonce${nonce}timestamp${timestamp}${appSecret})},,,)},,)}"
}

interface request parameter