# How to mask sensitive data in logstash

**URL:** <https://discuss.elastic.co/t/how-to-mask-sensitive-data-in-logstash/170333>\
**Category:** Logstash\
**Created:** [February 28, 2019, 12:04pm UTC](https://discuss.elastic.co/t/how-to-mask-sensitive-data-in-logstash/170333 "2019-02-28T12:04:36Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![manickalai](https://avatars.discourse-cdn.com/v4/letter/m/94ad74/32.png) [@manickalai](https://discuss.elastic.co/u/manickalai)\
**Post date:** [February 28, 2019, 12:04pm UTC](https://discuss.elastic.co/t/how-to-mask-sensitive-data-in-logstash/170333/1 "2019-02-28T12:04:36Z")

</div>

i have to mask the Card no : 712345678901236, OTP : 1234, expiryDate:01/01/2018, cvv:000, MobileNo:1234567890

the masked data should be  
Card no : 7123 **1236, OTP : 14, expiryDate://20** , cvv:\*\*, MobileNo:12\*\*\*\*\*\*\*90

kindly suggest the regex method

---

<div class="post-metadata">

**Author:** ![Badger](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/badger/32/25190_2.png) [@Badger](https://discuss.elastic.co/u/Badger)\
**Post date:** [February 28, 2019, 2:13pm UTC](https://discuss.elastic.co/t/how-to-mask-sensitive-data-in-logstash/170333/2 "2019-02-28T14:13:11Z")

</div>

Use mutate+gsub with capture groups. For example, to convert the card number to 71231236 you can use

```
mutate { gsub => ["message", "Card no : ([0-9]{4})[0-9]+([0-9]{4}),", "\1\2" ] }
```

---

<div class="post-metadata">

**Author:** ![manickalai](https://avatars.discourse-cdn.com/v4/letter/m/94ad74/32.png) [@manickalai](https://discuss.elastic.co/u/manickalai)\
**Post date:** [March 1, 2019, 12:27pm UTC](https://discuss.elastic.co/t/how-to-mask-sensitive-data-in-logstash/170333/3 "2019-03-01T12:27:51Z")

</div>

its will hide only card no, how about other entity?

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [March 29, 2019, 12:27pm UTC](https://discuss.elastic.co/t/how-to-mask-sensitive-data-in-logstash/170333/4 "2019-03-29T12:27:54Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
