Topic
14 replies Latest Post - ‏2012-11-28T06:48:00Z by SystemAdmin
SystemAdmin
SystemAdmin
162 Posts
ACCEPTED ANSWER

Pinned topic Code to encrypt the Password or any string

‏2007-07-12T08:26:46Z |
/// <summary>

/// Thsi method retrieve the string to encrypt from the Presentation Layer

/// And return the Encrypted String

/// </summary>

/// <param name="str"></param>

/// <returns></returns>

public string encryptPassword(string strText)

{

return Encrypt(strText, "&%#@?,:*");

}

/// <summary>

/// This method retrieve the encrypted string to decrypt from the Presentation Layer

/// And return the decrypted string

/// </summary>

/// <param name="str"></param>

/// <returns></returns>

public string decryptPassword(string str)

{

return Decrypt(str, "&%#@?,:*");

}

/// <summary>

/// This method has been used to get the Encrypetd string for the

/// passed string

/// </summary>

/// <param name="strText"></param>

/// <param name="strEncrypt"></param>

/// <returns></returns>

private string Encrypt(string strText, string strEncrypt)

{

byte[] byKey = new byte20;

byte[] dv ={ 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF };

try

{

byKey = System.Text.Encoding.UTF8.GetBytes(strEncrypt.Substring(0, 8));

DESCryptoServiceProvider des = new DESCryptoServiceProvider();

byte[] inputArray = System.Text.Encoding.UTF8.GetBytes(strText);

MemoryStream ms = new MemoryStream();

CryptoStream cs = new CryptoStream(ms, des.CreateEncryptor(byKey, dv), CryptoStreamMode.Write);

cs.Write(inputArray, 0, inputArray.Length);

cs.FlushFinalBlock();

return Convert.ToBase64String(ms.ToArray());

}

catch (Exception ex)

{

throw ex;

}

}

/// <summary>

/// This method has been used to Decrypt the Encrypted String

/// </summary>

/// <param name="strText"></param>

/// http://www.hanusoftware.com

/// <param name="strEncrypt"></param>

/// <returns></returns>

private string Decrypt(string strText, string strEncrypt)

{

byte[] bKey = new byte20;

byte[] IV = { 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF };

try

{

bKey = System.Text.Encoding.UTF8.GetBytes(strEncrypt.Substring(0, 8));

DESCryptoServiceProvider des = new DESCryptoServiceProvider();

Byte[] inputByteArray = inputByteArray = Convert.FromBase64String(strText);

MemoryStream ms = new MemoryStream();

CryptoStream cs = new CryptoStream(ms, des.CreateDecryptor(bKey, IV), CryptoStreamMode.Write);

cs.Write(inputByteArray, 0, inputByteArray.Length);

cs.FlushFinalBlock();

System.Text.Encoding encoding = System.Text.Encoding.UTF8;

return encoding.GetString(ms.ToArray());

}

catch (Exception ex)

{

throw ex;

}

}
[url=http://www.hanusoftware.com]Software Development India[/url]
Updated on 2012-11-28T06:48:00Z at 2012-11-28T06:48:00Z by SystemAdmin
  • SystemAdmin
    SystemAdmin
    162 Posts
    ACCEPTED ANSWER

    Re: Code to encrypt the Password or any string

    ‏2008-03-03T12:30:56Z  in response to SystemAdmin
    thanks for the valuable coding info
  • SystemAdmin
    SystemAdmin
    162 Posts
    ACCEPTED ANSWER

    Re: Code to encrypt the Password or any string

    ‏2008-05-27T13:48:15Z  in response to SystemAdmin
    Thanks for sharing!
    Web Developer
    CoNetrix - Information Security
  • SystemAdmin
    SystemAdmin
    162 Posts
    ACCEPTED ANSWER

    Re: Code to encrypt the Password or any string

    ‏2008-07-14T09:10:15Z  in response to SystemAdmin
    Nice code thanks for sharing ....

    Offshore software development company
  • SystemAdmin
    SystemAdmin
    162 Posts
    ACCEPTED ANSWER

    Re: Code to encrypt the Password or any string

    ‏2008-07-16T08:24:36Z  in response to SystemAdmin
    Thank you for sharing...

    IBM Server
  • SystemAdmin
    SystemAdmin
    162 Posts
    ACCEPTED ANSWER

    Re: Code to encrypt the Password or any string

    ‏2008-07-19T12:11:13Z  in response to SystemAdmin
    Hi,
    Thanks for sharing a valuable code with all of us...This type of postings are always valuable for all developer workin in .NET.

    <hr />

    Offshore Software Development
  • SARANSOFT
    SARANSOFT
    1 Post
    ACCEPTED ANSWER

    Re: Code to encrypt the Password or any string

    ‏2010-02-05T05:49:57Z  in response to SystemAdmin
    Owesome, really useful to us also. keep it up. thanks again.

    with regards,
    securenext software
    offshore software programmers | hire developers
    http://www.securenext.com
  • rozerdun
    rozerdun
    3 Posts
    ACCEPTED ANSWER

    Re: Code to encrypt the Password or any string

    ‏2011-10-05T10:53:48Z  in response to SystemAdmin
    Thanks for the code i was looking for this from last some of days.
    • zabalex
      zabalex
      9 Posts
      ACCEPTED ANSWER

      Re: Code to encrypt the Password or any string

      ‏2011-10-11T07:01:55Z  in response to rozerdun
      I was wondering if I could use this code to encypt URL and program it into Joomla website to load encrypted URLs of documents. In that case, visitor could not download files directly, but instnead would have to use my document viewer.

      Any suggestions?

      SEO San Francisco | website design
  • stuartthomas
    stuartthomas
    1 Post
    ACCEPTED ANSWER

    Re: Code to encrypt the Password or any string

    ‏2012-08-09T12:02:25Z  in response to SystemAdmin
    Hi Buddy,

    Thanks you so much sharing this code with all of us. I will be definite implement this code and hope it would be much helpful for developers. I would like to shared this with my company software developers and i thinks they would be more appreciated to this coding .

    Regards,
    http://www.vertexplus.com/
  • Tech369
    Tech369
    1 Post
    ACCEPTED ANSWER

    Re: Code to encrypt the Password or any string

    ‏2012-08-12T06:34:54Z  in response to SystemAdmin
    Thank you for sharing
  • SystemAdmin
    SystemAdmin
    162 Posts
    ACCEPTED ANSWER

    Re: Code to encrypt the Password or any string

    ‏2012-11-22T18:36:08Z  in response to SystemAdmin
    May I know how many bit encryption you have used in it ?
  • SystemAdmin
    SystemAdmin
    162 Posts
    ACCEPTED ANSWER

    Re: Code to encrypt the Password or any string

    ‏2012-11-28T06:48:00Z  in response to SystemAdmin
    Its really helpful information.
    Thanks for sharing this valuable information here for us.

    It is great to see this coding info.

    Warm Regards
    Sukumar Jena
    www.objectfrontier.com