Follow by Email

Thursday, 13 December 2012

Password Encryption and Decryption in C#.Net

Class Containing method of Name Encrypt and Decrypt :


using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Microsoft.VisualBasic;

/// <summary>
/// Summary description for clsPasswords
/// </summary>
public class clsPasswords
{
   
public clsPasswords()
{

}
    public string Encrypt(string strPwd)
    {
        string strEncrypted = "";
        int intClearChar=0;
        string strEncChar;
        int i;


        for (i = 1; i <= strPwd.Length; i++)
        {
            //intClearChar = Asc(Mid(strPwd, i, 1))
            //  intClearChar = Convert.ToInt32(Microsoft.VisualBasic.Strings.Mid(strPwd, i, 1));

         string strMid=   Microsoft.VisualBasic.Strings.Mid(strPwd, i, 1);

         foreach (char c in strMid)
         {
             intClearChar = (System.Convert.ToInt32(c));
         }

         strEncChar = Convert.ToChar(intClearChar + 3).ToString() + Convert.ToChar(intClearChar - 2).ToString() + Convert.ToChar(intClearChar + 5).ToString();

            strEncrypted = strEncrypted + strEncChar;

        }

        string strEncrypt = strEncrypted;

        return strEncrypt;
    }



    public string Decrypt(string strPwd)
    {
        string strDecrypted = "";
        int intChar=0;
        int intChar1, intChar2, intChar3;
        string strClearChar;
        int i;

        for (i = 1; i < strPwd.Length; i += 3)
        {

            string strMid = Microsoft.VisualBasic.Strings.Mid(strPwd, i, 1);

            foreach (char c in strMid)
            {
                intChar = (System.Convert.ToInt32(c));
            }

            //intChar = Convert.ToInt32(strPwd.Substring(i, 1));

            strClearChar = Convert.ToChar(intChar - 3).ToString();
            strDecrypted = strDecrypted + strClearChar;
        }

        string strDecrypt = strDecrypted;

        return strDecrypt;

    }


}


0 comments:

Post a Comment


                                                            

 
Design by Abhinav Ranjan Sinha