# Flask-Session-Cookie-Manager | Flask Session Cookie Decoder/Encoder

**URL:** <https://onehack.st/t/flask-session-cookie-manager-flask-session-cookie-decoder-encoder/100498>\
**Category:** Tools & Scripts\
**Tags:** programming, browsers\
**Created:** [August 12, 2020, 9:28pm UTC](https://onehack.st/t/flask-session-cookie-manager-flask-session-cookie-decoder-encoder/100498 "2020-08-12T21:28:06Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![BlueHacker](https://onehack.st/user_avatar/onehack.st/bluehacker/32/174721_2.png) [@BlueHacker](https://onehack.st/u/BlueHacker)\
**Post date:** [August 12, 2020, 9:28pm UTC](https://onehack.st/t/flask-session-cookie-manager-flask-session-cookie-decoder-encoder/100498/1 "2020-08-12T21:28:07Z")

</div>

![image](https://onehack.st/uploads/default/original/3X/d/4/d41231e335aec49e79c90b4d1ceb12d51e38b911.png)

Flask Session Cookie Decoder/Encoder

**Depencencies**

- Python 2 or Python 3
- [itsdangerous](https://pypi.python.org/pypi/itsdangerous)
- [Flask](https://pypi.python.org/pypi/Flask)

**Installation**

**BlackArch Linux**

```auto
# pacman -S flask-session-cookie-manager{3,2}

```

**Git**

**ArchLinux**  
Both python3 etn python2:

```auto
$ git clone https://github.com/noraj/flask-session-cookie-manager.git && cd flask-session-cookie-manager# makepkg -sic

```

**Other distros**  
Find your way with your package manager, use pip in a virtual environment or use [pyenv](https://github.com/pyenv/pyenv).  
Eg.

```auto
$ git clone https://github.com/noraj/flask-session-cookie-manager.git && cd flask-session-cookie-manager$ python -m venv venv$ source venv/bin/activate$ python setup.py install

```

**Usage**  
Use `flask_session_cookie_manager3.py` with Python 3 and `flask_session_cookie_manager2.py` with Python 2.

```auto
usage: flask_session_cookie_manager{2,3}.py [-h] {encode,decode} ...Flask Session Cookie Decoder/Encoderpositional arguments: {encode,decode} sub-command help encode encode decode decodeoptional arguments: -h, --help show this help message and exit

```

**Encode**

```auto
usage: flask_session_cookie_manager{2,3}.py encode [-h] -s <string> -t <string>optional arguments: -h, --help show this help message and exit -s <string>, --secret-key <string> Secret key -t <string>, --cookie-structure <string> Session cookie structure

```

**Decode**

```auto
usage: flask_session_cookie_manager.py decode [-h] [-s <string>] -c <string>optional arguments: -h, --help show this help message and exit -s <string>, --secret-key <string> Secret key -c <string>, --cookie-value <string> Session cookie value

```

**Examples**

**Encode**

```auto
$ python{2,3} flask_session_cookie_manager{2,3}.py encode -s '.{y]tR&sp&77RdO~u3@XAh#TalD@Oh~yOF_51H(QV};K|ghT^d' -t '{"number":"326410031505","username":"admin"}'eyJudW1iZXIiOnsiIGIiOiJNekkyTkRFd01ETXhOVEExIn0sInVzZXJuYW1lIjp7IiBiIjoiWVdSdGFXND0ifX0.DE2iRA.ig5KSlnmsDH4uhDpmsFRPupB5Vw

```

**Note** : the session cookie structure must be a valid python dictionary

**Decode**  
With secret key:

```auto
$ python{2,3} flask_session_cookie_manager{2,3}.py decode -c 'eyJudW1iZXIiOnsiIGIiOiJNekkyTkRFd01ETXhOVEExIn0sInVzZXJuYW1lIjp7IiBiIjoiWVdSdGFXND0ifX0.DE2iRA.ig5KSlnmsDH4uhDpmsFRPupB5Vw' -s '.{y]tR&sp&77RdO~u3@XAh#TalD@Oh~yOF_51H(QV};K|ghT^d'{u'username': 'admin', u'number': '326410031505'}

```

Without secret key (less pretty output):

```auto
$ python{2,3} flask_session_cookie_manager{2,3}.py decode -c 'eyJudW1iZXIiOnsiIGIiOiJNekkyTkRFd01ETXhOVEExIn0sInVzZXJuYW1lIjp7IiBiIjoiWVdSdGFXND0ifX0.DE2iRA.ig5KSlnmsDH4uhDpmsFRPupB5Vw'{"number":{" b":"MzI2NDEwMDMxNTA1"},"username":{" b":"YWRtaW4="}}

```

Original author : [**Wilson Sumanang**](https://github.com/saruberoz)  
Fixes and improvements author : [**Alexandre ZANNI**](https://github.com/noraj)  
Imported from [saruberoz.github.io](http://saruberoz.github.io/flask-session-cookie-decoder-slash-encoder)

## GitHub:

> **[GitHub - noraj/flask-session-cookie-manager: :cookie: Flask Session Cookie Decoder/Encoder](https://github.com/noraj/flask-session-cookie-manager)**
>
> :cookie: Flask Session Cookie Decoder/Encoder
