简体   繁体   中英

My output is of 256 length which is alpha-numeric while checking I got modulus and exponent in dev tools

My input : 09876543212
Modulus : 5ad283c0c4922f5c12a4c4040f7ec5cd316c984f4e74edc99bf92eb19f40f430b5903a1a4b8d0e39512205769c3575679ed2abf4516bd9cb6f5e3391b1cc2254babb63fb0cf8cb878438851cb3bbc4f3a1728ef6d84871b3ff1ec2f31361fc527e6ff87056712c9d72ebcb7536b50bc0856cc8c4c05088a41f83e954f3e49c91
Exponent : 10001
Output : is alpha numeric 256 length

From my under standing I come to now it is using rsa encryption and sha 256 to convert my output in precise length
Help me to use it in jmeter

What do you want exactly? RSA-encode your "input" with the public key create from your modulus and exponent?

If yes you can use a suitableJSR223 Test Element and the following sample code (you might need to amend it according to your needs)

def modulus = '5ad283c0c4922f5c12a4c4040f7ec5cd316c984f4e74edc99bf92eb19f40f430b5903a1a4b8d0e39512205769c3575679ed2abf4516bd9cb6f5e3391b1cc2254babb63fb0cf8cb878438851cb3bbc4f3a1728ef6d84871b3ff1ec2f31361fc527e6ff87056712c9d72ebcb7536b50bc0856cc8c4c05088a41f83e954f3e49c91'
def exponent = '10001'

def modulusInt = new BigInteger(modulus, 16)
def exponentInt = new BigInteger(exponent, 16)

def keySpec = new java.security.spec.RSAPublicKeySpec(modulusInt, exponentInt)
def keyFactory = java.security.KeyFactory.getInstance("RSA")

publicKey = keyFactory.generatePublic(keySpec)

def input = '09876543212'

def cipher = javax.crypto.Cipher.getInstance("RSA/ECB/NoPadding")
cipher.init(javax.crypto.Cipher.ENCRYPT_MODE, publicKey)

def encryptedValue = cipher.doFinal(input.getBytes())

log.info('Encrypted value: ' + encryptedValue.encodeBase64().toString())

Demo:

在此处输入图像描述

More information on Groovy scripting in JMeter: Apache Groovy: What Is Groovy Used For?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM