日期:2014-05-20  浏览次数:20387 次

DES的问题
private   string   iv   =   "23456789 ";
private   string   key   =   "34567890 ";
private   Encoding   encoding   =   new   UnicodeEncoding();
加密是这样的
  public   string   EncryptString(string   str)**************
                {
                        byte[]   ivb   =   Encoding.ASCII.GetBytes(this.iv);
                        byte[]   keyb   =   Encoding.ASCII.GetBytes(this.EncryptKey);//加密密钥
                        byte[]   toEncrypt   =   this.EncodingMode.GetBytes(str);//加密的内容
                        byte[]   encrypted;
                        ICryptoTransform   encryptor   =   des.CreateEncryptor(keyb,   ivb);
                        MemoryStream   msEncrypt   =   new   MemoryStream();
                        CryptoStream   csEncrypt   =   new   CryptoStream(msEncrypt,   encryptor,   CryptoStreamMode.Write);
                        csEncrypt.Write(toEncrypt,   0,   toEncrypt.Length);
                        csEncrypt.FlushFinalBlock();
                        encrypted   =   msEncrypt.ToArray();
                        csEncrypt.Close();
                        msEncrypt.Close();
                        //return   encrypted;***************************************
                        return   this.EncodingMode.GetString(encrypted);
                }
解密是
  public   string   DecryptString(string   str)**********************
                {
                        byte[]   ivb   =   Encoding.ASCII.GetBytes(this.iv);
                        byte[]   keyb   =   Encoding.ASCII.GetBytes(this.EncryptKey);
                        byte[]   toDecrypt   =   this.EncodingMode.GetBytes(str);**********
                        byte[]   deCrypted   =   new   byte[toDecrypt.Length];
                        ICryptoTransform   deCryptor   =   des.CreateDecryptor(keyb,   ivb);
                        MemoryStream   msDecrypt   =   new   MemoryStream(toDecrypt);
                        CryptoStream   csDecrypt   =   new   CryptoStream(msDecrypt,   deCryptor,   CryptoStreamMode.Read);