Topic
  • 14 replies
  • Latest Post - ‏2012-11-28T06:48:00Z by SystemAdmin
SystemAdmin
SystemAdmin
161 Posts

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
    161 Posts

    Re: Code to encrypt the Password or any string

    ‏2008-03-03T12:30:56Z  
    thanks for the valuable coding info
  • SystemAdmin
    SystemAdmin
    161 Posts

    Re: Code to encrypt the Password or any string

    ‏2008-05-27T13:48:15Z  
    Thanks for sharing!
    Web Developer
    CoNetrix - Information Security
  • SystemAdmin
    SystemAdmin
    161 Posts

    Re: Code to encrypt the Password or any string

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

    Offshore software development company
  • SystemAdmin
    SystemAdmin
    161 Posts

    Re: Code to encrypt the Password or any string

    ‏2008-07-16T08:24:36Z  
    Thank you for sharing...

    IBM Server
  • SystemAdmin
    SystemAdmin
    161 Posts

    Re: Code to encrypt the Password or any string

    ‏2008-07-19T12:11:13Z  
    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

    Re: Code to encrypt the Password or any string

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

    with regards,
    securenext software
    offshore software programmers | hire developers
    http://www.securenext.com
  • SaraMcdowell
    SaraMcdowell
    1 Post

    Re: Code to encrypt the Password or any string

    ‏2011-05-26T08:47:23Z  
    • SARANSOFT
    • ‏2010-02-05T05:49:57Z
    Owesome, really useful to us also. keep it up. thanks again.

    with regards,
    securenext software
    offshore software programmers | hire developers
    http://www.securenext.com
    Good info! Thank you for the post. The article is really the best on this laudable topic.

    Custom Application Development
  • rozerdun
    rozerdun
    3 Posts

    Re: Code to encrypt the Password or any string

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

    Re: Code to encrypt the Password or any string

    ‏2011-10-11T07:01:55Z  
    • rozerdun
    • ‏2011-10-05T10:53:48Z
    Thanks for the code i was looking for this from last some of days.
    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
  • steve71917
    steve71917
    1 Post

    Re: Code to encrypt the Password or any string

    ‏2012-04-03T07:01:43Z  
    • zabalex
    • ‏2011-10-11T07:01:55Z
    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
    Awesome coding. Really it will help many developers like me.

    iPhone Application Development
  • stuartthomas
    stuartthomas
    1 Post

    Re: Code to encrypt the Password or any string

    ‏2012-08-09T12:02:25Z  
    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

    Re: Code to encrypt the Password or any string

    ‏2012-08-12T06:34:54Z  
    Thank you for sharing
  • SystemAdmin
    SystemAdmin
    161 Posts

    Re: Code to encrypt the Password or any string

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

    Re: Code to encrypt the Password or any string

    ‏2012-11-28T06:48:00Z  
    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