2011-06-02 40 views
-4

我想在c#中很好的加密和解密算法?哪个是c#中最好的加密和解密算法?

我GOOGLE了一些网页,..我有一个,..

private string base64Encode(string sData) 
     { 
      try 
      { 
       byte[] encData_byte = new byte[sData.Length]; 
       encData_byte = System.Text.Encoding.UTF8.GetBytes(sData); 
       string encodedData = Convert.ToBase64String(encData_byte);    
       return encodedData; 
      } 
      catch (Exception ex) 
      { 
       throw new Exception("Error in base64Encode" + ex.Message); 
      } 
     } 

    public string base64Decode(string sData) 
     { 
      System.Text.UTF8Encoding encoder = new System.Text.UTF8Encoding(); 
      System.Text.Decoder utf8Decode = encoder.GetDecoder(); 
      byte[] todecode_byte = Convert.FromBase64String(sData); 
      int charCount = utf8Decode.GetCharCount(todecode_byte, 0, todecode_byte.Length); 
      char[] decoded_char = new char[charCount]; 
      utf8Decode.GetChars(todecode_byte, 0, todecode_byte.Length, decoded_char, 0); 
      string result = new String(decoded_char); 
      return result; 
     } 

是好?其他建议一个好的。

在此先感谢!

+8

Base64是*不*加密。 – 2011-06-02 11:04:33

+1

你想要什么? – 2011-06-02 11:06:21

+4

最佳解密算法是与加密算法相匹配的算法。 – Snowbear 2011-06-02 11:06:57

回答

2

第一种编码不是加密。

加密算法的选择将取决于解决方案的要求。没有抽象的最好。

您必须考虑所需的保护级别,必须执行操作的时间以及如何传输密钥。

+0

谢谢你!我现在很清楚! – Sagotharan 2011-06-03 12:44:06