如何在c#中编写解密代码

时间:2011-08-19 09:53:04

标签: c# asp.net encryption

编码字符串

代码:

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

2 个答案:

答案 0 :(得分:2)

public string Base64Decode(string data)
{
    byte[] byteArray = Convert.FromBase64String(data);
    var message = System.Text.Encoding.UTF8.GetString(byteArray);
    return message;
}

答案 1 :(得分:1)

查看Convert.FromBase64String