• λ我爱Aspx >> Asp.Net >> 从COM组件调用.NET组件编程实战
  • 从COM组件调用.NET组件编程实战

  • :未知  Դ:非寒日志  :2007-4-21 0:45:31  ؼ:.net,com
  • //使得输入密码必须输入英文文本

    des.Key = ASCIIEncoding.ASCII.GetBytes(sKey);

    des.IV = ASCIIEncoding.ASCII.GetBytes(sKey);

    MemoryStream ms = new MemoryStream();

    CryptoStream cs = new CryptoStream(ms, des.CreateEncryptor(),CryptoStreamMode.Write);

    //Write the byte array into the crypto stream

    //(It will end up in the memory stream)

    cs.Write(inputByteArray, 0, inputByteArray.Length);

    cs.FlushFinalBlock();

    //Get the data back from the memory stream, and into a string

    StringBuilder ret = new StringBuilder();

    foreach(byte b in ms.ToArray())

    {

    //Format as hex

    ret.AppendFormat("{0:X2}", b);

    }

    ret.ToString();

    return ret.ToString();

    }

    // 解密的方法

    public string Decrypt(string pToDecrypt, string sKey)

    {

    DESCryptoServiceProvider des = new DESCryptoServiceProvider();

    //Put the input string into the byte array

    byte[] inputByteArray = new byte[pToDecrypt.Length / 2];

    for(int x = 0; x < pToDecrypt.Length / 2; x++)

    {

    int i = (Convert.ToInt32(pToDecrypt.Substring(x * 2, 2), 16));

    inputByteArray[x] = (byte)i;

    }

    //建立加密对象的密钥和偏移量,此值重要,不能修改

    des.Key = ASCIIEncoding.ASCII.GetBytes(sKey);

    des.IV = ASCIIEncoding.ASCII.GetBytes(sKey);

    MemoryStream ms = new MemoryStream();

    CryptoStream cs = new CryptoStream(ms, des.CreateDecryptor(), CryptoStreamMode.Write);

    Ҷƪл˵?
  • һƪ在来三张
    һƪ乱画的一大堆哈哈