DESCryptoServiceProvider

        public static byte[] DESEncrypt(byte[] data, byte[] sKey)
        {
            return DESEncrypt(data, sKey, sKey);
        }
        /// <summary>
        /// CBC-DES加密
        /// </summary>
        public static byte[] DESEncrypt(byte[] data, byte[] key, byte[] iv)
        {
            //注:已省略检查参数合法性等代码,以缩短帖子长度
            byte[] result = null;
            using (DES des = new DESCryptoServiceProvider() { Key = key, IV = iv })
            {
                des.Mode = CipherMode.ECB;
                des.Padding = PaddingMode.None;
                result = des.CreateEncryptor().TransformFinalBlock(data, 0, data.Length);
            }
            return result;
        }
        public static byte[] DESDecrypt(byte[] data, byte[] sKey)
        {
            return DESDecrypt(data, sKey, sKey);
        }
        /// <summary>
        /// CBC-DES解密
        /// </summary>
        public static byte[] DESDecrypt(byte[] data, byte[] key, byte[] iv)
        {
            //注:已省略检查参数合法性等代码,以缩短帖子长度
            byte[] result = null;
            using (DES des = new DESCryptoServiceProvider() { Key = key, IV = iv })
            {
                des.Mode = CipherMode.ECB;
                des.Padding = PaddingMode.None;
                result = des.CreateDecryptor().TransformFinalBlock(data, 0, data.Length);
            }
            return result;
        }

 

posted @ 2016-07-28 23:31  shiningrise  阅读(620)  评论(0编辑  收藏  举报
// 侧边栏目录 // https://blog-static.cnblogs.com/files/douzujun/marvin.nav.my1502.css