0

Possible Duplicate:
How to encrypt a string in .NET?

Which one is the most excellent and toughest encryption for String type data in C#..

Community
  • 1
  • 1
Inv Xaasha
  • 83
  • 1
  • 2
  • 9

3 Answers3

2

That really depends on your exact requirements.

Most modern encryption algorithms are probably more than strong enough for your needs if you use them properly.

The weak point in your system will not be the encryption algorithm itself. Almost every other aspect of your setup will be more vulnerable to attack than the algorithm.

LukeH
  • 263,068
  • 57
  • 365
  • 409
1

My primary answer is "it depends upon what you're doing with that string". This question (and answers) will guide you...

.NET Secure Memory Structures

... but it depends if you're encyrpting/security that string in memory, how you're persisting it, how you intend using that string and how you intend disposing of it.

These SO questions touch on these topics too..

How to encrypt a string in .NET?

What's the best way to encrypt short strings in .NET?

... and contain useful links.

Community
  • 1
  • 1
Martin Peck
  • 11,440
  • 2
  • 42
  • 69
  • Thanks Much ! anyhow i am using MD5 hash for encrypting string and put the encrypted string in loop with 10 iterations. e.g encryptedstr = EncryptString(encryptedstr); is it ok? – Inv Xaasha Dec 02 '10 at 13:12
  • md5 is a hash-function(one way), and no encryption(reversible). Do you want to securely save a password? – CodesInChaos Dec 02 '10 at 13:17
  • @Inv Xaasha, MD5 isn't encryption at all, as there is no way to get it back. If a secure hash does what you need (you don't need a way to get it back), and you are worried about the relative lack of security in MD5, then go with one of the SHA-2 family, like SHA-256. – Jon Hanna Dec 02 '10 at 14:45
0

That would be a one-time pad. If correctly implemented it's been proved to be impossible to crack but an OTP is most probably not a viable option for you.

RSA encryption is very secure and .NET supports it. But since asymmetric encryption is only designed for encrypting data smaller than it's key size it's often not a great choice for encryption of arbitrary strings. That leads us to block ciphers and among those I would recommend AES.

Jonas Elfström
  • 30,834
  • 6
  • 70
  • 106
  • Of course one can combine asymmetric and symmetric when one needs the functionality of the former with the performance of the latter: Randomly create a symmetric key, encrypt the data with that, then use asymmetric to encrypt the symmetric key. Send (store, whatever) the encrypted key along with the encrypted data. – Jon Hanna Dec 02 '10 at 14:47