# Base64 decode issue

**URL:** <https://discuss.elastic.co/t/base64-decode-issue/319874>\
**Category:** Logstash\
**Created:** [November 27, 2022, 5:31am UTC](https://discuss.elastic.co/t/base64-decode-issue/319874 "2022-11-27T05:31:33Z")\
**Posts on this page:** 1\
**Showing post:** 2

<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:** [November 27, 2022, 5:14pm UTC](https://discuss.elastic.co/t/base64-decode-issue/319874/2 "2022-11-27T17:14:45Z")

</div>

> [@Rajesh\_R](#):
>
> ruby { code =\> 'event.set("decoded", Base64.decode64(event.get("payload")))' }

That will decode the base64 and result in

```
"decoded" => "<?xml\xC2\xA0version=\"1.0\"\xC2\xA0encoding=\"ISO-8859-1\"?>\xC2\xA0\xC2\xA0<note>

```

The \xC2\xA0 are non-breaking spaces in UTF-8, but the decoded string is ASCII-8BIT (puts Base64.decode64(event.get("payload")).encoding.name will tell you that).

So the default encoding is wrong. You can change it using

```
ruby { code => 'event.set("decoded", Base64.decode64(event.get("payload")).force_encoding("UTF-8"))' }

```

which will result in

```
"decoded" => "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?> <note> <to>Tove</to>...

```

Note that an xml filter will not parse non-breaking spaces, so you need to replace them if you want to parse the XML

```
mutate { gsub => ["decoded", "[[:space:]]", " " ] }

```

---

_[View the full topic](https://discuss.elastic.co/t/base64-decode-issue/319874)._
