开发者

Encode and Decode a string in c#

Hii, I had a requirement of encode a string provided to a unreadable f开发者_如何学编程ormat and also have to decode after certain action performed. I have tried 'Base64' encoding. But this is not a secure way. I need some other solutions. Give some help regarding the above context.


You could use a symmetric encryption algorithm. Here's an example. Both sides (encrypt/decrypt) must share a common secret key for this to work.


You're looking for symmetric encryption. There are several libraries in C# available. You could use RijndaelManaged for example. See this SQ question for an example


See following
http://www.codeproject.com/KB/cs/Cryptography.aspx
http://www.codeproject.com/KB/security/DotNetCrypto.aspx

Here is an example using RSA. Replace your_rsa_key with your RSA key.

System.Security.Cryptography.RSACryptoServiceProvider Provider =
                new System.Security.Cryptography.RSACryptoServiceProvider();
Provider.ImportParameters(your_rsa_key);
byte[] encrypted = Provider.Encrypt(System.Text.Encoding.UTF8.GetBytes("Hello World!"), true);
string decrypted = System.Text.Encoding.UTF8.GetString(Provider.Decrypt(encrypted, true));


The System.Security.Cryptography namespace can help you. But when choosing your encryption algorithm take in mind the size of data you are trying to encrypt and the level of security you want to achieve.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜