Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is a good method for obfuscating a base 64 string?

Base64 encoding is often used to obfuscate plaintext, I am wondering if there are any quick/easy ways of obfuscating a base 64 string, so that it is not easily recognizeable as such. To do so the method should obfuscate the padding characters (='s) such that they become some other symbol and are more dispersed.

Does anyone know of an easy (and easily reversible) way to do this?

You could use a shift cipher, but I am looking for something that's a little more comprehensive, for example if my shift cipher mapped = to a, someone might notice a string that frequently ends in a's.

The purpose is not to add security, it is actually simply to make base64 unrecognizeable as base 64. It also does not need to pass a security proffesional, just an individual that knows what base64 is and what it looks like. Ex (='s at the end etc.)

The method I describe would probably add non base 64 characters, like ^%$#@!, to help obfuscate the reader.

Most of the replies seem to be on the topic of WHY I would want to do this, and the basic answer is that the operation would be completed numerous times (So I want something inexpensive), and done in a way where no password can be remembered (Why I don't XOR). Also the data isn't highly sensitive, and is just to be used as a method against the casual user, who might have knowledge of what a base 64 string is.

like image 494
Shane Chin Avatar asked Feb 05 '26 06:02

Shane Chin


2 Answers

A couple of suggestions:

  1. Strip any ending = (according to Wikipedia they are no needed) and then bitwise negate each byte. This will transform the text into mostly non-readable characters.
  2. Loop over the data and xor each character with it's position, modulo 256. This will eliminate any simple statistical analysis since the mapping of each character depends on the position in the string.
like image 80
Anders Abel Avatar answered Feb 06 '26 19:02

Anders Abel


In contrast to one of the points in Anders Abel's best answer, the = signs in the base64 strings seem to matter:

$ echo -n foobar | base64 
Zm9vYmFy
$ echo -n foobar1 | base64 
Zm9vYmFyMQ==
$ echo -n Zm9vYmFyMQ | base64 -D
foobar$ echo -n Zm9vYmFyMQ= | base64 -D
foobar$ echo -n Zm9vYmFyMQ== | base64 -D
foobar1$
like image 32
munene Avatar answered Feb 06 '26 19:02

munene



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!