JMeter User
JMeter User

Reputation: 21

JMeter - JsenEncrypt using Groovy so not to overload js load during each thread call for encryption

JMeter using jsr223 preprocessor wanted to use groovy as language. How to convert present code to groovy so that below code don't cause any performance bottlenecks when executed as part of each thread

The script looks like this:

enter image description here

Upvotes: 1

Views: 872

Answers (1)

Dmitri T
Dmitri T

Reputation: 168147

I strongly doubt that your code works given it relies on this JSEncrypt library


With regards to your question itself, you can use JDK Securit API in order to encrypt whatever string you want using whatever algorithm you like.

Example Groovy code:

def cipher = javax.crypto.Cipher.getInstance('RSA')
def factory = java.security.KeyFactory.getInstance("RSA")
def publicKeyString='your_public_key_here'
def  encodedKeySpec = new java.security.spec.X509EncodedKeySpec(publicKeyString.decodeBase64())
def publicKey = factory.generatePublic(encodedKeySpec)
cipher.init(javax.crypto.Cipher.ENCRYPT_MODE, publicKey)
cipherText = cipher.doFinal('the string you want to encode'.getBytes())
log.info('Encrypted: ' + cipherText.encodeBase64())

Demo:

enter image description here

More information: Apache Groovy - Why and How You Should Use It

Upvotes: 1

Related Questions