Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Best way to obfuscate an email address

I'm creating an application that requires passing email addresses around in querystrings and linking to these pages in public documents.

I'd like to prevent my site from becoming spambot heaven, so I'm looking for a simple algorithm (preferably in JavaScript) to encrypt/obfuscate the address so it can be used publicly ina URL without making the email address an easy target.

ex

www.mysite.com/[email protected]
 to
www.mysite.com/page.php?e=aed3Gfd469201

Preferably the result would be a short-ish string that could easily be used in a URL. Any suggestions for what algorithm I could use?

like image 629
MarathonStudios Avatar asked Aug 10 '10 02:08

MarathonStudios


People also ask

Why do people spell out email addresses?

Address munging is the practice of disguising an e-mail address to prevent it from being automatically collected by unsolicited bulk e-mail providers.

How does Cloudflare email obfuscation work?

By enabling Cloudflare Email Address Obfuscation, email addresses on your web page will be obfuscated (hidden) from bots, while keeping them visible to humans. In fact, there are no visible changes to your website for visitors.

What is email decode?

It obfuscates (scrambles) email addresses in HTML to prevent bots from scraping them from your site.


3 Answers

RSA-encrypt the data using the public key corresponding to a private key held only by your site.

Base64 and urlencode the result.

like image 150
Borealid Avatar answered Oct 14 '22 05:10

Borealid


you can make a simple function, which would xor each char value with some integer, and make a hex encoded string. (email addresses do not contain non-ascii characters, so it won't complicate with multibyte chars). e.g.:

obfusc = function(s, c) {
  c = c || 0x7f;
  r = "";
  for (i in s) {
    valh = (s.charCodeAt(i) ^ c).toString(16);
    if (valh.length == 1) valh = "0" + valh;
    r += valh;
  };
  return r;
}

deobfusc = function(s, c) {
  c = c || 0x7f;
  r = "";
  for (var i=0; i<(s.length/2); i++) {
    r += String.fromCharCode(parseInt(s.substr(i*2, 2), 16) ^ c)
  };
  return r;
}

addr = "[email protected]";
x = obfusc(addr);
alert(addr + " -> " + x + " -> " + deobfusc(x))

// [email protected] -> 15101a3f1a071e120f131a511c1012 -> [email protected]
like image 23
mykhal Avatar answered Oct 14 '22 04:10

mykhal


Some options coming to my mind :)

like image 40
Nikita Rybak Avatar answered Oct 14 '22 04:10

Nikita Rybak