JMeter jsencrypt using groovy

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

JMeter jsencrypt using groovy

UserJMeter999
Looking for groovy equivalent code to perform below actions to avoid
performance overload when below code is called bu each thread before send
DOB

load("jsencrypt.js");

var DOB = "12/03/1990";
var publicKey =
"64886a70d01010105000382020a003082020a02820201009d865a469cd1672a01";
var encrypt = new JSEncrypt.JSEncrypt();
encrypt.setPublicKey(publicKey);
var encrypted = encrypt.encrypt(password);
log.info("Encryped " + encrypted);


PS: jsencrypt.js is placed in bin folder of Jmeter installations



--
Sent from: http://www.jmeter-archive.org/JMeter-User-f512775.html

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: JMeter jsencrypt using groovy

glinius@live.com
You're looking for the code in the wrong place, my expectation is that you
should rather be using freelancer marketplaces or your friends/colleagues
rather than asking the members of JMeter mailing list to do your job for
you. As an exception here is how you can use  Java Security API
<https://docs.oracle.com/javase/tutorial/security/apisign/index.html>   and
Groovy language in order to perform RSA encryption of a string using a
public key:
> 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())

More information:  Apache Groovy - Why and How You Should Use It
<https://www.blazemeter.com/blog/groovy-new-black/>  



--
Sent from: http://www.jmeter-archive.org/JMeter-User-f512775.html
Reply | Threaded
Open this post in threaded view
|

Re: JMeter jsencrypt using groovy

UserJMeter999
When i run below i get invalid key exception

def cipher = javax.crypto.Cipher.getInstance('RSA')
def factory = java.security.KeyFactory.getInstance("RSA")
def
PKEY='30820222300d06092a864886f70d01010105000382020f003082020a02820201009d865a469cd1672fe3dfcd9f15a8d4bb22de008a9f60748919aa8b2996\n'+
'c04004b91f74553616b64b7d6d2626bef38f7a0dbd788d7026ef2ab4993eb77e551fda1569b31e81656e20629ec070730462e8c12b8ba79447fd7afb00de656a199878\n'+
'2149154d94d3be6ef2453365442c3830b6b609b2218d7481306f98bbffc7c44683fb520d68415ca73108e10b5790f5a32b73a6ee739748144173f71eddfbd7963f7746\n'+
'f229b95b3c4c5159c715d393e0e193108a932763d6d80d429a98e48e3ad8149128d19fc87ebaec0a51f9a538ba618dc6c198e5fbd41798aa9e491796e208cc5d089e14\n'+
'1e33beffd4f0ac46a10a40661d36cfadad63f9bbb8b9f55ad17c0b5460a965cf302d1c98aa17e7569dae540f403571d9fc2b035e5809a0ca59583ec52a96877b6dccc4\n'+
'12642eb4e2e39ba0867401846627b14ee152651c15cd4459357d33f88b81fe45498db4cfa449f9b1f500f882c6f2e590bf32490a76cc6a362d4d431c69b8f40c726aaa\n'+
'2162a721f204b7bec551edd3c440fec346ff772515dea570ecac7ca7e478aa5d47c6fa122d51e6419776c7bdd99f7562274e77f25347a8669f8855a37192b6f93ff99b\n'+
'f992d620e953d7c38dc184f8b520d267814311d480d927f6da1903f34bf9686f9a0c9f6d10b9b02965ea8eb770cc449e3f80e089f9d0e4f5ede6660d52a807a2b8e90b\n'+
'0904e427295453fbcfd4ccffdd590203010001'
def  encodedKeySpec = new
java.security.spec.X509EncodedKeySpec(PKEY.decodeBase64())
def publicKey = factory.generatePublic(encodedKeySpec)
cipher.init(javax.crypto.Cipher.ENCRYPT_MODE, publicKey)
cipherText = cipher.doFinal('1110020323'.getBytes())
log.info('Encrypted: ' + cipherText.encodeBase64())



--
Sent from: http://www.jmeter-archive.org/JMeter-User-f512775.html

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: JMeter jsencrypt using groovy

UserJMeter999
In reply to this post by glinius@live.com
I get exception JSR223 Sampler, message: javax.script.ScriptException:
java.security.spec.InvalidKeySpecException:
java.security.InvalidKeyException: invalid key format
javax.script.ScriptException: java.security.spec.InvalidKeySpecException:
java.security.InvalidKeyException: invalid key format


def cipher = javax.crypto.Cipher.getInstance('RSA')
def factory = java.security.KeyFactory.getInstance("RSA")
def
PKEY='30820222300d06092a864886f70d01010105000382020f003082020a02820201009d865a469cd1672fe3dfcd9f15a8d4bb22de008a9f60748919aa8b2996\n'+
'c04004b91f74553616b64b7d6d2626bef38f7a0dbd788d7026ef2ab4993eb77e551fda1569b31e81656e20629ec070730462e8c12b8ba79447fd7afb00de656a199878\n'+
'2149154d94d3be6ef2453365442c3830b6b609b2218d7481306f98bbffc7c44683fb520d68415ca73108e10b5790f5a32b73a6ee739748144173f71eddfbd7963f7746\n'+
'f229b95b3c4c5159c715d393e0e193108a932763d6d80d429a98e48e3ad8149128d19fc87ebaec0a51f9a538ba618dc6c198e5fbd41798aa9e491796e208cc5d089e14\n'+
'1e33beffd4f0ac46a10a40661d36cfadad63f9bbb8b9f55ad17c0b5460a965cf302d1c98aa17e7569dae540f403571d9fc2b035e5809a0ca59583ec52a96877b6dccc4\n'+
'12642eb4e2e39ba0867401846627b14ee152651c15cd4459357d33f88b81fe45498db4cfa449f9b1f500f882c6f2e590bf32490a76cc6a362d4d431c69b8f40c726aaa\n'+
'2162a721f204b7bec551edd3c440fec346ff772515dea570ecac7ca7e478aa5d47c6fa122d51e6419776c7bdd99f7562274e77f25347a8669f8855a37192b6f93ff99b\n'+
'f992d620e953d7c38dc184f8b520d267814311d480d927f6da1903f34bf9686f9a0c9f6d10b9b02965ea8eb770cc449e3f80e089f9d0e4f5ede6660d52a807a2b8e90b\n'+
'0904e427295453fbcfd4ccffdd590203010001'
def  encodedKeySpec = new
java.security.spec.X509EncodedKeySpec(PKEY.decodeBase64())
def publicKey = factory.generatePublic(encodedKeySpec)
cipher.init(javax.crypto.Cipher.ENCRYPT_MODE, publicKey)
cipherText = cipher.doFinal('1110020323'.getBytes())
log.info('Encrypted: ' + cipherText.encodeBase64())



--
Sent from: http://www.jmeter-archive.org/JMeter-User-f512775.html

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: JMeter jsencrypt using groovy

Felix Schumacher
The key doesn't look like it is base64 encoded. It looks like hex encoded.

Felix

Am 21. Oktober 2019 21:33:39 MESZ schrieb UserJMeter999 <[hidden email]>:

>I get exception JSR223 Sampler, message: javax.script.ScriptException:
>java.security.spec.InvalidKeySpecException:
>java.security.InvalidKeyException: invalid key format
>javax.script.ScriptException:
>java.security.spec.InvalidKeySpecException:
>java.security.InvalidKeyException: invalid key format
>
>
>def cipher = javax.crypto.Cipher.getInstance('RSA')
>def factory = java.security.KeyFactory.getInstance("RSA")
>def
>PKEY='30820222300d06092a864886f70d01010105000382020f003082020a02820201009d865a469cd1672fe3dfcd9f15a8d4bb22de008a9f60748919aa8b2996\n'+
>'c04004b91f74553616b64b7d6d2626bef38f7a0dbd788d7026ef2ab4993eb77e551fda1569b31e81656e20629ec070730462e8c12b8ba79447fd7afb00de656a199878\n'+
>'2149154d94d3be6ef2453365442c3830b6b609b2218d7481306f98bbffc7c44683fb520d68415ca73108e10b5790f5a32b73a6ee739748144173f71eddfbd7963f7746\n'+
>'f229b95b3c4c5159c715d393e0e193108a932763d6d80d429a98e48e3ad8149128d19fc87ebaec0a51f9a538ba618dc6c198e5fbd41798aa9e491796e208cc5d089e14\n'+
>'1e33beffd4f0ac46a10a40661d36cfadad63f9bbb8b9f55ad17c0b5460a965cf302d1c98aa17e7569dae540f403571d9fc2b035e5809a0ca59583ec52a96877b6dccc4\n'+
>'12642eb4e2e39ba0867401846627b14ee152651c15cd4459357d33f88b81fe45498db4cfa449f9b1f500f882c6f2e590bf32490a76cc6a362d4d431c69b8f40c726aaa\n'+
>'2162a721f204b7bec551edd3c440fec346ff772515dea570ecac7ca7e478aa5d47c6fa122d51e6419776c7bdd99f7562274e77f25347a8669f8855a37192b6f93ff99b\n'+
>'f992d620e953d7c38dc184f8b520d267814311d480d927f6da1903f34bf9686f9a0c9f6d10b9b02965ea8eb770cc449e3f80e089f9d0e4f5ede6660d52a807a2b8e90b\n'+
>'0904e427295453fbcfd4ccffdd590203010001'
>def  encodedKeySpec = new
>java.security.spec.X509EncodedKeySpec(PKEY.decodeBase64())
>def publicKey = factory.generatePublic(encodedKeySpec)
>cipher.init(javax.crypto.Cipher.ENCRYPT_MODE, publicKey)
>cipherText = cipher.doFinal('1110020323'.getBytes())
>log.info('Encrypted: ' + cipherText.encodeBase64())
>
>
>
>--
>Sent from: http://www.jmeter-archive.org/JMeter-User-f512775.html
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: [hidden email]
>For additional commands, e-mail: [hidden email]
Reply | Threaded
Open this post in threaded view
|

Re: JMeter jsencrypt using groovy

UserJMeter999
Developer are using *JsenEncrypt* for encrypting the input values



--
Sent from: http://www.jmeter-archive.org/JMeter-User-f512775.html

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]