7

I'm looking for a fast and secure cryptography algorithm with C# implementation. I need to be able to restore the initial message. What could you suggest?

Thank you for your help!

StuffHappens
  • 6,457
  • 13
  • 70
  • 95
  • 1
    Do you need symmetric or asymmetric encryption? – NullUserException Aug 13 '10 at 06:20
  • 2
    It doesn't matter. I need the algorithm to be fast and secure. – StuffHappens Aug 13 '10 at 06:27
  • 5
    There is no such thing as "fast and secure". How fast? Are we talking MBs per second, GBs per second, TBs per second? How secure? Secure against your sister? Secure against your competitors? Secure against government agencies? – Damien_The_Unbeliever Aug 13 '10 at 06:34
  • 1
    Damien has a good point. Your trade-off is performance vs security. The more secure it is, the slower it will be. 256-bit AES is pretty good and I think it's fast enough. – NullUserException Aug 13 '10 at 06:41
  • 1
    Actually, StuffHappens is talking about storing key in code - that may not be as secure as he wishes to be regardless of encryption algorithm he chooses – VinayC Aug 13 '10 at 06:58
  • @Stuff: "It doesn't matter". Oh yes it does. – H H Aug 13 '10 at 07:41
  • Possible duplicate of [Encrypt and decrypt a string](http://stackoverflow.com/questions/202011/encrypt-and-decrypt-a-string) – Liam Mar 11 '16 at 10:54

2 Answers2

9

If you need asymmetric encryption, use 2048-bits RSA.

If you can get away with symmetric encryption, use 256-bit AES.

MSDN Reference:

System.Security.Cryptography
RSACryptoServiceProvider
AesCryptoServiceProvider

You can read about the difference between them here: Symmetric versus Asymmetric.

Community
  • 1
  • 1
NullUserException
  • 83,810
  • 28
  • 209
  • 234
  • 1
    Symmetric versus Asymmetric, link is dead. new one here: http://support.microsoft.com/kb/246071 – string.Empty Dec 22 '13 at 00:51
  • @string.Empty also the new link is dead, here another link good be helpful https://www.geeksforgeeks.org/difference-between-symmetric-and-asymmetric-key-encryption/ – Henka Programmer Aug 31 '22 at 12:35
2

Based on your comments, symmetric encryption should do the trick for you - not to mention it would be faster than asymmetric one. You may want to look at RijndaelManaged class - its same as AES implementation but you have more flexibility in terms of block sizes.

Now, talking about security, it would depend upon how secure is your key. In your case, you are talking about storing it in code. So you need to secure your code/assemblies (say if it is going to lie on controlled server environment). A better option would be to put key in config file (provided config files are stored in controlled environment, they offers flexibility of changing it). In case, you wish to put in code and code/assembly but want to protect from reverse-engineering attacks - obfuscation coupled with Steganography would be way to go. Below are couple of articles on Steganography implementations in .NET:

VinayC
  • 47,395
  • 5
  • 59
  • 72