1

I have a text box when we enter the value in to text box and we click on save button the encrypted version of text box value will be stored in database and when we retrieving the value it must be decrypted.

I don't know how to do this - would any one help on this topic.

Tim Lloyd
  • 37,954
  • 10
  • 100
  • 130
user682417
  • 1,478
  • 4
  • 25
  • 46

3 Answers3

2

See this SO discussion - it should answer your question of how to encrypt and decrypt a string using C#. See also, the .NET Cryptography namespace.

Community
  • 1
  • 1
mikemanne
  • 3,535
  • 1
  • 22
  • 30
0

http://support.microsoft.com/kb/307020 explains one method of taking hashes of two strings and comparing them together.

Shaun Hamman
  • 2,287
  • 4
  • 21
  • 33
-1

When you say encrypt I assume you mean a hash? You really shouldn't be able to decrypt a users password. Usually what you do is take a hash store it in the DB, then whenever you need to validate the password you ask the user for it, hash that value and compare the user entered hash and the hash stored in the database.

There are a variety or hashing algorithms; .NET has several built in MD5 and several SHA algorithms.

MSDN has a lot of great links on taking a hash and using that.

Justin
  • 4,002
  • 2
  • 19
  • 21
  • that is not a password textbox ... the value entered in that text box is string ..... – user682417 Jul 27 '11 at 14:58
  • Whether the OP was talking specifically about a password or not, the methodology is the same. Hash the input string, store it in the database, then compare the hashed version of a second input string against that hash. If you actually want to get the original string on a retrieval, is it really necessary to hash it in the first place? – Shaun Hamman Jul 27 '11 at 15:04
  • @user682417 I posted an answer with the requested information. – Shaun Hamman Jul 27 '11 at 15:13