Skip to content

Instantly share code, notes, and snippets.

@joeegan
Created January 11, 2011 01:03
Show Gist options
  • Save joeegan/773807 to your computer and use it in GitHub Desktop.
Save joeegan/773807 to your computer and use it in GitHub Desktop.
js encrypt and decrypt email address
// html
<script type="text/javascript" src="http://crypto-js.googlecode.com/files/2.0.0-crypto-min.js"></script>
<script type="text/javascript" src="write-email.js"></script>
<a id="contact" href=""></a>
// contents of write-email.js
Egan.contact = Crypto.charenc.Binary.stringToBytes("myname@myemailaddress.com");
// Lastly (after html is confirmed to be loaded)....
Egan.writeEmailAddress = function() {
var unencryptedEmail = Crypto.charenc.Binary.bytesToString(Egan.contact),
element = document.getElementById('contact');
element.innerHTML = unencryptedEmail;
element.setAttribute('href', 'mailto:'+unencryptedEmail);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment