# how to encrypt the password?

**URL:** <https://community.gatling.io/t/how-to-encrypt-the-password/2027>\
**Category:** Gatling (Open-Source)\
**Created:** [February 18, 2015, 3:33pm UTC](https://community.gatling.io/t/how-to-encrypt-the-password/2027 "2015-02-18T15:33:00Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![Tal\_Salman](https://avatars.discourse-cdn.com/v4/letter/t/8797f3/32.png) [@Tal\_Salman](https://community.gatling.io/u/Tal_Salman)\
**Post date:** [February 18, 2015, 3:33pm UTC](https://community.gatling.io/t/how-to-encrypt-the-password/2027/1 "2015-02-18T15:33:00Z")

</div>

```auto
i use this in my code:

```

```auto

```

```auto
.queryParam("j_username",session("randomUser"))

```

---

<div class="post-metadata">

**Author:** ![slandelle](https://dub1.discourse-cdn.com/flex013/user_avatar/community.gatling.io/slandelle/32/4_2.png) [@slandelle](https://community.gatling.io/u/slandelle)\
**Post date:** [February 18, 2015, 3:44pm UTC](https://community.gatling.io/t/how-to-encrypt-the-password/2027/2 "2015-02-18T15:44:45Z")

</div>

Gatling just send the value that you pass (but the value here would be UrlEncoded).  
If your application performs encryption on the client side, it’s your responsibility to do the same in Gatling.

---

<div class="post-metadata">

**Author:** ![Tal\_Salman](https://avatars.discourse-cdn.com/v4/letter/t/8797f3/32.png) [@Tal\_Salman](https://community.gatling.io/u/Tal_Salman)\
**Post date:** [February 22, 2015, 8:25am UTC](https://community.gatling.io/t/how-to-encrypt-the-password/2027/3 "2015-02-22T08:25:34Z")

</div>

i just want to send the password in a way that will not be show in the other side.  
i have tried:

```auto
.queryParam("j_password","xxxx").asFormUrlEncoded

```

```auto
is this the way you mean?

```

```auto
i have debugged it and i see in Charles that the user is appear.

```

```auto
why?

```

```auto

```

---

<div class="post-metadata">

**Author:** ![slandelle](https://dub1.discourse-cdn.com/flex013/user_avatar/community.gatling.io/slandelle/32/4_2.png) [@slandelle](https://community.gatling.io/u/slandelle)\
**Post date:** [February 22, 2015, 8:40am UTC](https://community.gatling.io/t/how-to-encrypt-the-password/2027/4 "2015-02-22T08:40:28Z")

</div>

It looks like you’re confusing query params (that appear in the url’s query) and form params (used for encoding params in the request body, typical form-url-encoded Content-Type).

---

<div class="post-metadata">

**Author:** ![Tal\_Salman](https://avatars.discourse-cdn.com/v4/letter/t/8797f3/32.png) [@Tal\_Salman](https://community.gatling.io/u/Tal_Salman)\
**Post date:** [February 22, 2015, 12:27pm UTC](https://community.gatling.io/t/how-to-encrypt-the-password/2027/5 "2015-02-22T12:27:45Z")

</div>

ok but it still not help me how to do it 🙂

---

<div class="post-metadata">

**Author:** ![slandelle](https://dub1.discourse-cdn.com/flex013/user_avatar/community.gatling.io/slandelle/32/4_2.png) [@slandelle](https://community.gatling.io/u/slandelle)\
**Post date:** [February 22, 2015, 2:17pm UTC](https://community.gatling.io/t/how-to-encrypt-the-password/2027/6 "2015-02-22T14:17:20Z")

</div>

What you’re asking is everything but clear.  
The title of your thread is about encryption. Then, you’re asking about queryParam. And then about form-url-encoded.

Please explain what you’re trying to do. If this has nothing to do about encryption, but you just want to post a single form, use [formParam](http://gatling.io/docs/2.1.4/http/http_request.html#parameters).

---

<div class="post-metadata">

**Author:** ![Tal\_Salman](https://avatars.discourse-cdn.com/v4/letter/t/8797f3/32.png) [@Tal\_Salman](https://community.gatling.io/u/Tal_Salman)\
**Post date:** [February 22, 2015, 2:45pm UTC](https://community.gatling.io/t/how-to-encrypt-the-password/2027/7 "2015-02-22T14:45:06Z")

</div>

i just want that the password value will be encoded. it is always needed in password no ? i see that by default you do it in gatling and if you don’t want it u use disableUrlEncoding.  
so maybe i don’t need to do nothing.  
but actually i see the password in monitor charles.

---

<div class="post-metadata">

**Author:** ![slandelle](https://dub1.discourse-cdn.com/flex013/user_avatar/community.gatling.io/slandelle/32/4_2.png) [@slandelle](https://community.gatling.io/u/slandelle)\
**Post date:** [February 22, 2015, 3:06pm UTC](https://community.gatling.io/t/how-to-encrypt-the-password/2027/8 "2015-02-22T15:06:47Z")

</div>

HTML deal with passwords in any special way, password type inputs will be sent over HTTP as plain text, just like any other field, hence securing the transport layer with HTTPS.

---

<div class="post-metadata">

**Author:** ![Tal\_Salman](https://avatars.discourse-cdn.com/v4/letter/t/8797f3/32.png) [@Tal\_Salman](https://community.gatling.io/u/Tal_Salman)\
**Post date:** [February 22, 2015, 3:21pm UTC](https://community.gatling.io/t/how-to-encrypt-the-password/2027/9 "2015-02-22T15:21:04Z")

</div>

so nothing to be done on it.  
i am just wondering what is in jmeter in http request in the section “send parameters with the request”, when you add user name, password… parameters, there is also a column called Encode? usually, i check it.

---

<div class="post-metadata">

**Author:** ![slandelle](https://dub1.discourse-cdn.com/flex013/user_avatar/community.gatling.io/slandelle/32/4_2.png) [@slandelle](https://community.gatling.io/u/slandelle)\
**Post date:** [February 22, 2015, 3:33pm UTC](https://community.gatling.io/t/how-to-encrypt-the-password/2027/10 "2015-02-22T15:33:24Z")

</div>

Form and query parameters have to be encoding (in similar but different ways). Note that it’s “encoded” (which is about transforming some reserved characters), NOT “encrypted” (which is about cryptography).  
I guess this checkbox is about if the values you feed have been already encoded or not, so the values don’t get encoded twice. Gatling has a similar feature (encoding is enabled by default, but you can disable it).

---

<div class="post-metadata">

**Author:** ![Abhinav\_Gogna](https://avatars.discourse-cdn.com/v4/letter/a/c0e974/32.png) [@Abhinav\_Gogna](https://community.gatling.io/u/Abhinav_Gogna)\
**Post date:** [February 23, 2015, 4:23am UTC](https://community.gatling.io/t/how-to-encrypt-the-password/2027/11 "2015-02-23T04:23:16Z")

</div>

Tal,

Usually people encode/encrypt passwords, in case, someone else come across there script, they wont see the password in clear text.

At work, we are also required to encode/encrypt passwords in scripts. I simply created a simple java class and imported in my simulations. Here is the java class.

`  
import java.security._;  
import java.security.spec.InvalidKeySpecException;  
import javax.crypto._;  
import sun.misc.\*;  
import javax.crypto.spec.SecretKeySpec;

public class StringCrypto {

private static final String ALGO = “AES”;  
private static final byte[] keyValue =  
new byte[] { ‘G’, ‘A’, ‘t’, ‘l’, ‘i’, ‘n’, ‘g’, ‘i’, ‘s’, ‘a’, ‘w’,‘e’, ‘s’, ‘o’, ‘m’, ‘e’ };

public static String encrypt(String Data) throws Exception {  
Key key = generateKey();  
Cipher c = Cipher.getInstance(ALGO);  
c.init(Cipher.ENCRYPT\_MODE, key);  
byte[] encVal = c.doFinal(Data.getBytes());  
String encryptedValue = new BASE64Encoder().encode(encVal);  
return encryptedValue;  
}

public static String decrypt(String encryptedData) throws Exception {  
Key key = generateKey();  
Cipher c = Cipher.getInstance(ALGO);  
c.init(Cipher.DECRYPT\_MODE, key);  
byte[] decordedValue = new BASE64Decoder().decodeBuffer(encryptedData);  
byte[] decValue = c.doFinal(decordedValue);  
String decryptedValue = new String(decValue);  
return decryptedValue;  
}  
private static Key generateKey() throws Exception {  
Key key = new SecretKeySpec(keyValue, ALGO);  
return key;  
}

public static void main(String args[]){

}

}  
`

HTH

---

<div class="post-metadata">

**Author:** ![puttur\_jaya](https://avatars.discourse-cdn.com/v4/letter/p/f17d59/32.png) [@puttur\_jaya](https://community.gatling.io/u/puttur_jaya)\
**Post date:** [May 18, 2017, 10:55am UTC](https://community.gatling.io/t/how-to-encrypt-the-password/2027/12 "2017-05-18T10:55:23Z")

</div>

> > .exec(http(“request\_2”)  
> > .post(“/jm/auth/oauth/v2/token”)  
> > .header(“Content-Type”, “application/x-www-form-urlencoded”)  
> > .headers(headers\_2)  
> > .formParam(“username”, “${username}”)  
> > .formParam(“password”, “${password}”)  
> > .formParam(“grant\_type”, “password”)  
> > .digestAuth(“login”,“pass”)  
> > .basicAuth(“l7xx3e887403b5ed40e78ca8edef65c87587”,“c645568a927745a696e0e52e5871be83”)  
> > .resources(http(“request\_3”)  
> > .get(“/cr/v2/wallet/users/profile/query”)  
> > .headers(headers\_3)))

in above request iam getting encoded username and password in basicAuth, so please help me to pass authentiction request?
