zoukankan      html  css  js  c++  java
  • net 加密-解密

     #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
    
  • 相关阅读:
    蒟蒻的sb对拍方法
    LuoguP5176 公约数 题解
    天守阁的地板 题解
    Crash的数字表格 / JZPTAB 题解
    于神之怒加强版 简要题解
    最小公倍数之和 题解
    莫比乌斯反演的计算
    YY的GCD 题解
    acwing 309装饰围栏 大致思路 (预览)
    错排问题(预览)
  • 原文地址:https://www.cnblogs.com/linzhao126/p/3417175.html
Copyright © 2011-2022 走看看