Click here to Skip to main content
15,906,333 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi, I want to encrypt some strings in C#, I want to know which encryption is most powerful and how can I use it inside of my code.

And also what kind of encryption Microsoft uses to encrypt auth cookies?

Thanks in advance.
Posted
Comments
DaveAuld 16-Aug-11 6:12am    
You need to think about the 'cost' of the encryption and how much 'value' you place on the data. If you just want to stop casual browsing of some settings etc then you don't need complicated encryption, does the encrypted data need to be shared, does it reside locally and only used by the app etc.

C#
var provider = new System.Security.Cryptography.RSACryptoServiceProvider(); provider.ImportParameters(your_rsa_key);  

var encryptedBytes = provider.Encrypt(     System.Text.Encoding.UTF8.GetBytes("Hello World!"), true);  

string decryptedTest = System.Text.Encoding.UTF8.GetString(provider.Decrypt(encryptedBytes, true)); 


For more info, visit MSDN - RSACryptoServiceProvider
On MSDN[^]
 
Share this answer
 
v2
Look at this article, and the table within as you can see SHA512 is as teh author puts it extreme, but slow in comparison to other algo's.
.NET Encryption Simplified[^]


As for your second question i think SHA1 is used for auth cookies by default, but you could probably verify that by searching the Docs.
 
Share this answer
 
It isn't a case of "most powerful" it's a case of "what do you want to do with them?"

If you need to securely transfer them between two people, than you want to look ate the Public Key encryption facilities.
If you want to encrypt them to secure file contents for a single user, then look at DES.
If you are talking passwords, then don't encrypt them, use a hashing algorithm instead.

And the biggest "most powerful" has bugger-all to do with which algorithm you chose: it's how your code works, and what the humans involved do with the keys...
 
Share this answer
 
Comments
Alireza Loghmani 16-Aug-11 6:46am    
I mean "powerful", fast and hard to crack.
BobJanova 16-Aug-11 7:17am    
Those two things are in direct competition with each other. That is rather the point of the answers.
Alireza Loghmani 16-Aug-11 7:24am    
I just defined it.
BobJanova 16-Aug-11 8:22am    
No you didn't ... you say you want both options of a mutually exclusive choice. Anything which is harder to crack is a more complex algorithm and therefore slower (at least in the context of serious encryption algorithms which don't have dumb mistakes leading to shortcuts).
OriginalGriff 16-Aug-11 7:23am    
It still depends on what you want to do with it. - and as BobJaniova says, "fast" and "hard" are normally exclusive...
SHA1 is "fast" and "hard to crack" because it is a hashing algorithm which you can't reverse to recover the original input, that doesn't mean it is suitable for encrypting files.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900