日期:2014-05-17  浏览次数:20431 次

asp.net 密码加密解密求教
密文这个
HpqLcUFnd/0tOzZcVogh2w== 


C# code
private void Button2_Click(object sender, EventArgs e)
{
    string text = this.p.Text;
    string v = ConfigurationSettings.AppSettings["ConnectionString"];
    switch (v)
    {
        case null:
        case string.Empty:
            throw new ApplicationException("web.config中应该包含  <appSettings><add key=\"ConnectionString_da\" value=\"数据连接串\" /></appSettings> ");
    }
    int index = v.IndexOf("password=");
    int num2 = v.IndexOf(";", index);
    string str3 = v.Substring(index + 9, (num2 - index) - 9);
    text = "NMGrskssok3";
    v = v.Replace("password=" + str3, "password=" + cStr.Encrypting(text, this.PublicKey));
    this.SaveWeb("ConnectionString", v);
    this.SaveWeb("ConnectionString_da", v);
    base.Response.Write("<script>alert('密码修改成功!')</script>");
}

 

dll里修改密码的代码


这个是
this.PublicKey
C# code
 this.PublicKey = "@(1Qz1)#";



求这个密码的加密方式是什么。怎么解密

------解决方案--------------------
呵呵,它使用 GetLegalKey(pCryptoService, Key); 将字符串转换为字节数组(你还应该看看他是怎么转换的),然后作为key,对Source按照ascii编码转换的字节数据进行des加密。然后对加密之后的数据内容,只取第一个0字节值之前的那些字节,进行base64编码成为字符串。

假如说它抛弃0字节值以后的字节是有意义的(即确实抛弃了一些值),那么这个所谓加密可能就没有什么解密的意义。因为解密会丢失一部分原始内容。

如果需要解密,当然是首先将base64字符串重新转换为字节数组,然后使用des解密(其key可以复制这里的GetLegalKey代码),得到的字节数组再使用ascii编码方式转换为字符串。这就是解密。这不复杂,不过写代码很琐碎(需要测试),看看别人能不能给你写吧。