The. NET system. Text. asciiencoding and system. bitconvertor classes work together to encrypt strings on the server. The client uses JavaScript to decrypt strings. The Code is as follows:
<Script language = "JavaScript">
/*
========================================================== ============================
This function helps protect the email address from the edevil spam-bots
That Scan Web pages for useful data such as (email addresses ).
Instead of using the data directly, the encoded value is stored in
HTML and decoded when required.
========================================================== ============================
*/
Function decode (serverencoded)
{
// The serverencoded parameter is a string that contains the encoded data.
// Each character in the serverencoded parameter has been converted
// A two digit number (hex/base16). This function converts
// Series of numbers back into the normal form and returns
// Decoded string to the client
// Holds the decoded string
VaR res = "";
// Go through and decode the full input server encoded string
For (I = 0; I <serverencoded. length ;)
{
// Holds each letter (2 digits)
VaR letter = "";
Letter = serverencoded. charat (I) + serverencoded. charat (I + 1)
// Build the real decoded Value
Res + = string. fromcharcode (parseint (letter, 16 ));
I + = 2;
}
// Return the new decoded string to allow it to be rendered to screen
Return res;
}
/*
========================================================== ============================
This function gets a reference to the server encrypted string and
Then decrypts this using the decode () function and sets
Txtdecrypted value to the value return by the decode () function
========================================================== ============================
*/
Function getemailanddecode (){
// Get the table <a class = IAS style = "font-weight: normal; font-size: 100%; padding-bottom: 1px; color: darkgreen; border-bottom: darkgreen 0.07em solid; Background-color: transparent; text-Decoration: underline "href =" # "target = _ blank itxtdid =" 3146774 "> element </a>
VaR txtsvrencr = Document. getelementbyid ('txtserverencrypted ');
VaR txtjsdecr = Document. getelementbyid ('txtdecrypted ');
Txtjsdecr. value = decode (txtsvrencr. value );
VaR txtalltog = Document. getelementbyid ('txtalltogether ');
Txtalltog. value = decode (txtalltog. value );
}
</SCRIPT>
Public partial class _ default: system. Web. UI. Page
{
Protected void page_load (Object sender, eventargs E)
{
# Region email encryption
// If Javascript is enabled do the Encoding
If (request. browser. Javascript)
{
// Do the encryption using the raw email
Txtserverencrypted. Text = system. bitconverter. tostring (
System. Text. asciiencoding. ASCII. getbytes (
(Txtrawemail. Text). Replace ("-","");
// Do the encryption using the raw email
Txtalltogether. Text = system. bitconverter. tostring (
System. Text. asciiencoding. ASCII. getbytes (
(Txtrawemail. Text). Replace ("-","");
}
Else
{
// Couldnt find JavaScript so just use normal email
Txtserverencrypted. Text = txtrawemail. text;
Txtalltogether. Text = txtrawemail. text;
}
# Endregion
}
}
For details, see simple web based obfuscation.