public string Decrypt(string pToDecrypt, string sKey)
{
DESCryptoServiceProvider provider1 = new DESCryptoServiceProvider();
byte[] buffer1 = new byte[pToDecrypt.Length / 2];
for (int num1 = 0; num1 < (pToDecrypt.Length / 2); num1++)
{
int num2 = Convert.ToInt32(pToDecrypt.Substring(num1 * 2, 2), 0x10);
buffer1[num1] = (byte) num2;
}
provider1.Key = Encoding.ASCII.GetBytes(sKey);
provider1.IV = Encoding.ASCII.GetBytes(sKey);
MemoryStream stream1 = new MemoryStream();
CryptoStream stream2 = new CryptoStream(stream1, provider1.CreateDecryptor(), CryptoStreamMode.Write);
stream2.Write(buffer1, 0, buffer1.Length);
stream2.FlushFinalBlock();
StringBuilder builder1 = new StringBuilder();
return Encoding.Default.GetString(stream1.ToArray());
}
==============================================
以上是解密的方法。
调用是这样的:this.Decrypt("48FC50F3F5EB1A4B9CF9FA16765A4812", "2%b<5X7*");
"48FC50F3F5EB1A4B9CF9FA16765A4812" 是"127.0.0.1"加密后的字符
"2%b<5X7*" 是KEY我想问的是这个:"48FC50F3F5EB1A4B9CF9FA16765A4812"
是通过加密过来的。他的长度是32位。我不知道是怎么加密过来的!
谁能告诉我怎么样才能达到这样的效果?我自己写了一个加密
public string Encryptor(string pToEncryptor, string sKey)
{
DESCryptoServiceProvider provider1 = new DESCryptoServiceProvider(); byte[] buffer1 = ASCIIEncoding.Default.GetBytes(pToEncryptor); provider1.Key = Encoding.ASCII.GetBytes(sKey);
provider1.IV = Encoding.ASCII.GetBytes(sKey);
MemoryStream stream1 = new MemoryStream();
CryptoStream stream2 = new CryptoStream(stream1, provider1.CreateEncryptor(), CryptoStreamMode.Write);
stream2.Write(buffer1, 0, buffer1.Length);
stream2.FlushFinalBlock();
StringBuilder builder1 = new StringBuilder();
return Encoding.Default.GetString(stream1.ToArray());
}但是出来的String 是一堆不知道是什么的String

解决方案 »

  1.   

    把stream1.ToArray()的每个字节转换成16进制数字,再连起来
      

  2.   

    现在写这样 好象还是不行
    public string Encryptor(string pToEncryptor, string sKey)
    {
    DESCryptoServiceProvider provider1 = new DESCryptoServiceProvider(); byte[] buffer1 = ASCIIEncoding.Default.GetBytes(pToEncryptor); provider1.Key = Encoding.ASCII.GetBytes(sKey);
    provider1.IV = Encoding.ASCII.GetBytes(sKey);
    MemoryStream stream1 = new MemoryStream();
    CryptoStream stream2 = new CryptoStream(stream1, provider1.CreateEncryptor(), CryptoStreamMode.Write);
    stream2.Write(buffer1, 0, buffer1.Length);
    stream2.FlushFinalBlock();
    StringBuilder builder1 = new StringBuilder();
    string n = null;
    for(int i=0;i<stream1.ToArray().Length;i++)
    {
    n += Convert.ToInt32((stream1.ToArray())[i]).ToString();
    }

    return n;
    }
      

  3.   

    哪个高手能把我写个个加密的方法

    string=127.0.0.1
    key="2%b<5X7*"
    加密后变成"48FC50F3F5EB1A4B9CF9FA16765A4812"
      

  4.   

    //byte[] Data = Encoding.ASCII.GetBytes("IrisSkin is good !!!");
                    
    //sha1 crypto service, digital signatures are created from the hash
                    //string datastr = Convert.ToBase64String(Data); // DSA-SHA1 算法
                    if (!SkinEngine.DSA.VerifyData(SkinEngine.DSAHash, Convert.FromBase64String(base.Engine.SerialNumber)))byte[] SignedValue = Convert.FromBase64String("flcRzsRtDNr2XBiCoY7NrAC352AiFA/4YuLs4nDCyOHZX5xvWtgH/g==");
    textBox1.Text = Convert.ToBase64String(SignedValue); this.Text = dsa.VerifyData(Data, SignedValue).ToString();
      

  5.   

    System.Security.Cryptography.DSACryptoServiceProvider dsa = new DSACryptoServiceProvider(); DSAParameters p = new DSAParameters();
    p.Counter = 31;
    p.X = Convert.FromBase64String("SXJpc1NraW4gaXMgZ29vZCAhISE=");
    p.P = Convert.FromBase64String("v7aWx402hheC7WRlmLBlBE/DL3CI8b/Vmj/dCEQRMao1kVRmGL/fWhJGrnQUg4OU/cISGW1+DSu/iIhSKBZV4Q==");
    p.Q = Convert.FromBase64String("qRjCfkW/dk6mL4iUSTb5dZTKx30=");
    p.G = Convert.FromBase64String("aXWT+c/HfeIDCPzilyuoMXd1tHV3n1uiBa35dDRZqZ25o9PmMtaeHIBZAGPik5/qhDGf+sGm76QAGs5PzmM3dA==");
    p.Seed = Convert.FromBase64String("Z7UfhiqEbRBHn4yq4GYjuX/XMFI=");

    dsa.ImportParameters(p);
      

  6.   

    string text1 = "abcdefghigklmnopqrstuvwxyzABCDEFGHIGKLMNOPQRSTUVWXYZ0123456789`~!@#$%^&*()_+|-=[]{};':<>?,./";
                            string text2 = text1.Substring(0x36, 1) + text1.Substring(0x44, 1) + text1.Substring(1, 1) + text1.Substring(0x56, 1) + text1.Substring(0x39, 1) + text1.Substring(0x31, 1) + text1.Substring(0x3b, 1) + text1.Substring(0x47, 1);
                            string text3 = _Default.Decrypt(SifuData.UserDn(), text2);
                            string text4 = _Default.Decrypt("48FC50F3F5EB1A4B9CF9FA16765A4812", text2);
                            string text5 = _Default.Decrypt("24D673EB0598C4C8CD7A07F2B31E321B", text2);
                            string text6 = base.Request.Url.AbsoluteUri.ToLower();这个里面也有跟楼上写的有点类似。
    "abcdefghigklmnopqrstuvwxyzABCDEFGHIGKLMNOPQRSTUVWXYZ0123456789`~!@#$%^&*()_+|-=[]{};':<>?,./"楼上你给我的这段代码我越看越糊涂。。
    能不能帮忙把方法完整的写一下啊?
      

  7.   

    string text1 = "abcdefghigklmnopqrstuvwxyzABCDEFGHIGKLMNOPQRSTUVWXYZ0123456789`~!@#$%^&*()_+|-=[]{};':<>?,./";
                            string text2 = text1.Substring(0x36, 1) + text1.Substring(0x44, 1) + text1.Substring(1, 1) + text1.Substring(0x56, 1) + text1.Substring(0x39, 1) + text1.Substring(0x31, 1) + text1.Substring(0x3b, 1) + text1.Substring(0x47, 1);
                            string text3 = _Default.Decrypt(SifuData.UserDn(), text2);
                            string text4 = _Default.Decrypt("48FC50F3F5EB1A4B9CF9FA16765A4812", text2);
                            string text5 = _Default.Decrypt("24D673EB0598C4C8CD7A07F2B31E321B", text2);
                            string text6 = base.Request.Url.AbsoluteUri.ToLower();这个里面也有跟楼上写的有点类似。
    "abcdefghigklmnopqrstuvwxyzABCDEFGHIGKLMNOPQRSTUVWXYZ0123456789`~!@#$%^&*()_+|-=[]{};':<>?,./"楼上你给我的这段代码我越看越糊涂。。
    能不能帮忙把方法完整的写一下啊?
      

  8.   

    string text1 = "abcdefghigklmnopqrstuvwxyzABCDEFGHIGKLMNOPQRSTUVWXYZ0123456789`~!@#$%^&*()_+|-=[]{};':<>?,./";
                            string text2 = text1.Substring(0x36, 1) + text1.Substring(0x44, 1) + text1.Substring(1, 1) + text1.Substring(0x56, 1) + text1.Substring(0x39, 1) + text1.Substring(0x31, 1) + text1.Substring(0x3b, 1) + text1.Substring(0x47, 1);
                            string text3 = _Default.Decrypt(SifuData.UserDn(), text2);
                            string text4 = _Default.Decrypt("48FC50F3F5EB1A4B9CF9FA16765A4812", text2);
                            string text5 = _Default.Decrypt("24D673EB0598C4C8CD7A07F2B31E321B", text2);
                            string text6 = base.Request.Url.AbsoluteUri.ToLower();这个里面也有跟楼上写的有点类似。
    "abcdefghigklmnopqrstuvwxyzABCDEFGHIGKLMNOPQRSTUVWXYZ0123456789`~!@#$%^&*()_+|-=[]{};':<>?,./"
      

  9.   

    你的思路是对的,但需要稍微改动一下 public static string Encryptor(string pToEncryptor, string sKey)
    {
     DESCryptoServiceProvider provider1 = new DESCryptoServiceProvider();  byte[] buffer1 = ASCIIEncoding.Default.GetBytes(pToEncryptor);  provider1.Key = Encoding.ASCII.GetBytes(sKey);
     provider1.IV = Encoding.ASCII.GetBytes(sKey);
     MemoryStream stream1 = new MemoryStream();
     CryptoStream stream2 = new CryptoStream(stream1, provider1.CreateEncryptor(), CryptoStreamMode.Write);
     stream2.Write(buffer1, 0, buffer1.Length);
     stream2.FlushFinalBlock();
     StringBuilder builder1 = new StringBuilder();
    byte[] buffer2 =stream1.ToArray();
    for(int i=0;i<buffer2.Length;i++)
    {
    builder1.Append(buffer2[i].ToString("X"));
    }
     return builder1.ToString();
    }
      

  10.   

    楼上的代码现改一个地方,
    builder1.Append(buffer2[i].ToString("X"));
    改为
    builder1.Append(buffer2[i].ToString("X2"));测试实现楼主的要求
      

  11.   

    数据加密类库和实例下载 
     
    说明:数据加密类库和实例,可以对字符串,流,文件进行tripledes加密,也可以生成md5密文
    开发语言:C#
    开放工具版本:vs2005
    主要知识点:tripledes加密相关方法的掌握
    开发者:codestudy 
    联系方式:www.codestudy.cn 
    下载地址:
    http://www.codestudy.cn/showtopic-4.aspx