Jack Nicholson Jack Nicholson - 2 years ago 115
Python Question

php - Encode string two-way to move to another server

I have a string that is user input that is sent from one server to another using python. This string is then put through 'sed' to input it into a file.

This input cannot contain all sorts of characters such as:


Or it will break the code... I know right, good design!!.... /s

Is there a way for me to encrypt it to only an alphanumeric string like:


Which I can then decrypt on the other end back to the original string containing all the annoying characters that break code?

I have tried to look online but I can't find this specific issue.


Answer Source

Use Base64. It converts any data into an ASCII string.

Online encoder/decoder: base64decode.org


This is a string --> VGhpcyBpcyBhIHN0cmluZw==
StackOverflow    --> U3RhY2tPdmVyZmxvdw==
foobar           --> Zm9vYmFy

Note that the encoded data will be about 4/3 the size of the original data.

(Base85/Acii85 is the same thing but a little bit more compact)

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download