#region DES加密 解密
    //key:32位
        public string DESEncrypt(string strSource, byte[] key)
        {
            System.Security.Cryptography.SymmetricAlgorithm sa = System.Security.Cryptography.Rijndael.Create();
            sa.Key = key;
            sa.Mode = System.Security.Cryptography.CipherMode.ECB;
            sa.Padding = System.Security.Cryptography.PaddingMode.Zeros;
            System.IO.MemoryStream ms = new System.IO.MemoryStream();
            System.Security.Cryptography.CryptoStream cs = new System.Security.Cryptography.CryptoStream(ms, sa.CreateEncryptor(), System.Security.Cryptography.CryptoStreamMode.Write);
            byte[] byt = System.Text.Encoding.Unicode.GetBytes(strSource);
            cs.Write(byt, 0, byt.Length);
            cs.FlushFinalBlock();
            cs.Close();
            return Convert.ToBase64String(ms.ToArray());

        }
        public string DESDecrypt(string strSource,byte[] key)
        {
            System.Security.Cryptography.SymmetricAlgorithm sa = System.Security.Cryptography.Rijndael.Create();
            sa.Key = key;
            sa.Mode = System.Security.Cryptography.CipherMode.ECB;
            sa.Padding = System.Security.Cryptography.PaddingMode.Zeros;
            System.Security.Cryptography.ICryptoTransform ct = sa.CreateDecryptor();
            byte[] byt =  Convert.FromBase64String(strSource);
            System.IO.MemoryStream ms = new System.IO.MemoryStream();
            System.Security.Cryptography.CryptoStream cs = new System.Security.Cryptography.CryptoStream(ms, ct, System.Security.Cryptography.CryptoStreamMode.Write);
            cs.Write(byt,0,byt.Length);
            cs.FlushFinalBlock();
            cs.Close();
            return System.Text.Encoding.Unicode.GetString(ms.ToArray());
        } 
        #endregion

 

相关文章:

  • 2021-12-05
  • 2021-08-05
  • 2019-09-30
  • 2021-07-19
猜你喜欢
  • 2021-11-15
  • 2021-07-09
  • 2021-11-23
  • 2021-06-06
  • 2022-12-23
  • 2021-09-03
相关资源
相似解决方案