# Encoding

Na computação, encoding é o processo de transpor uma sequência de caracteres (letras, números, pontuações, caracteres especiais, símbolos) em um formato que seja eficiente para transmissão e storage.

O formato que comumente utilizamos é o [Base64](https://pt.wikipedia.org/wiki/Base64).

Funciona mais ou menos assim:

{% code title="Code" lineNumbers="true" %}

```go
package main

import (
  b64 "encoding/base64"
  "fmt"
)

func main() {
  // aqui está a string a ser encodada
  data := "abc123!?$*&()'-=@~"

  // realizamos o encoding
  sEnc := b64.StdEncoding.EncodeToString([]byte(data))
  fmt.Println(sEnc)

  // realizamos o decoding
  sDec, _ := b64.StdEncoding.DecodeString(sEnc)
  fmt.Println(string(sDec))
}
```

{% endcode %}

{% code title="Output" %}

```
YWJjMTIzIT8kKiYoKSctPUB+
abc123!?$*&()'-=@~
```

{% endcode %}

"Ok, mas para que utilizaremos isso?" Você deve estar se perguntado.

Imagine você tendo que transferir um trecho de código para outro computador.

Um exemplo como este:

{% code title="Request com Query Escape em GO" lineNumbers="true" %}

```go
package main

import (
    "fmt"
    "net/url"
)

func main() {
    s := "this will be esc@ped!"
    fmt.Println("http://example.com/say?message="+url.QueryEscape(s))
}
```

{% endcode %}

Temos `novas linhas`, `caracteres especiais`, etc...

Talvez alguma informação pode ser perdida no meio deste processo dependendo do conteúdo a ser transmitido.

Então transmitir este valor aqui é melhor não?

{% code title="Base64" overflow="wrap" %}

```
cGFja2FnZSBtYWluCgppbXBvcnQgKAogICAgImZtdCIKICAgICJuZXQvdXJsIgopCgpmdW5jIG1haW4oKSB7CiAgICBzIDo9ICJ0aGlzIHdpbGwgYmUgZXNjQHBlZCEiCiAgICBmbXQuUHJpbnRsbigiaHR0cDovL2V4YW1wbGUuY29tL3NheT9tZXNzYWdlPSIrdXJsLlF1ZXJ5RXNjYXBlKHMpKQp9
```

{% endcode %}

Você pode testar você mesmo com o [IT-TOOLS](https://it-tools.tech/base64-string-converter).

Antes de partirmos para o próximo tópico, vale lembrar:

{% hint style="warning" %}
Encoding NÃO É CRIPTOGRAFIA
{% endhint %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://ben-hurs-organization.gitbook.io/guia-de-appsec/cheat-sheets/encoding.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
