日期:2014-05-18  浏览次数:20987 次

DES加密
网上有很多DES加密字符串的算法,请问下自己加密字节数组,返回字节数组可以吗?
C# code

        public static byte[] Encode(byte[] data)
        {
            byte[] byKey = KEY_64;
            byte[] byIV = IV_64;
            DESCryptoServiceProvider cryptoProvider = new DESCryptoServiceProvider();
            int i = cryptoProvider.KeySize;
            MemoryStream ms = new MemoryStream();
            CryptoStream cst = new CryptoStream(ms, cryptoProvider.CreateEncryptor(byKey, byIV), CryptoStreamMode.Write);
            cst.Write(data, 0, data.Length);
            cst.FlushFinalBlock();

            byte[] buffer = ms.GetBuffer();
            return buffer;
         }

      public static byte[] Decode(byte[] data)
        {
            byte[] byKey = KEY_64;
            byte[] byIV = IV_64;
            byte[] byEnc;
            byEnc = data;
            DESCryptoServiceProvider cryptoProvider = new DESCryptoServiceProvider();
            MemoryStream ms = new MemoryStream();
            CryptoStream cst = new CryptoStream(ms, cryptoProvider.CreateDecryptor(byKey, byIV), CryptoStreamMode.Read);
            cst.Read(byEnc, 0, (int)byEnc.Length);
            cst.FlushFinalBlock();
            byte[] buffer = new byte[ms.Length];
            ms.Read(buffer, 0, (int)ms.Length);
            return buffer;
       }


好像不可以啊!请指教!

------解决方案--------------------
可以啊。你自己可以实现一个加密的算法,对字符串进行加密就OK了