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;
        }

 

相关文章:

  • 2021-10-01
  • 2021-12-08
  • 2022-12-23
  • 2022-12-23
  • 2021-10-31
  • 2021-11-24
猜你喜欢
  • 2022-12-23
  • 2021-11-20
  • 2022-12-23
  • 2022-02-21
  • 2022-12-23
  • 2021-07-14
  • 2022-01-01
相关资源
相似解决方案