1

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

Masud Jahan
  • 3,418
  • 2
  • 22
  • 35

1 Answers1

1

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

blackgreen
  • 34,072
  • 23
  • 111
  • 129
Dmitri T
  • 159,985
  • 5
  • 83
  • 133