Thursday 9 February 2012

HOW TO USE ENCRYPTION & DECRYPTION METHOD IN ASP.NET



string NORMAL = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
string ENCRYPT = "YO17KPLVSU50C8WE64GAI3MB2DFNZQ9JXTRH";
string strInput = "MamtaDevi";
string strEncrypted = string.Empty;
string strDecrypted = string.Empty;
string strNewChar;
string strLtr;
int iIdx;
protected EncryptionDecryptionDemo()
   {
    Response.Write(strInput);
    Response.Write("<br />");
    for (int i = 0; i < strInput.Length; i++)
   {
    strLtr = strInput.Substring(i, 1).ToUpper();
    iIdx = NORMAL.IndexOf(strLtr);
    strNewChar = ENCRYPT.Substring(iIdx, 1).ToUpper();
    strEncrypted += strNewChar;
    }
    Response.Write(strEncrypted);
    Response.Write("<br />");

    for (int i = 0; i < strInput.Length; i++)
    {
    strLtr = strEncrypted.Substring(i, 1).ToUpper();
    iIdx = ENCRYPT.IndexOf(strLtr);
    strNewChar = NORMAL.Substring(iIdx, 1).ToUpper();
    strDecrypted += strNewChar;
    }
    Response.Write(strDecrypted);
    }

If you want to use any special characters you can add in variable "NORMAL" and equivalent encrypted value in variable "ENCRYPT".
"ENCRYPT" variable has the reordered letters of "NORMAL" variable.

=====================================================================


No comments:

Post a Comment