首页
学习
活动
专区
工具
TVP
发布
精选内容/技术社群/优惠产品,尽在小程序
立即前往
  • 您找到你想要的搜索结果了吗?
    是的
    没有找到

    Asp.Net 加密解密

    #region DES加密解密 ///

    /// DES加密 /// /// <param name="strSource">待加密字串</param> /// <param name="key">32位Key值</param> /// <returns>加密后的字符串</returns> public string DESEncrypt(string strSource) { return DESEncrypt(strSource, DESKey); } public string DESEncrypt(string strSource, byte[] key) { SymmetricAlgorithm sa = Rijndael.Create(); sa.Key = key; sa.Mode = CipherMode.ECB; sa.Padding = PaddingMode.Zeros; MemoryStream ms = new MemoryStream(); CryptoStream cs = new CryptoStream(ms, sa.CreateEncryptor(), CryptoStreamMode.Write); byte[] byt = Encoding.Unicode.GetBytes(strSource); cs.Write(byt, 0, byt.Length); cs.FlushFinalBlock(); cs.Close(); return Convert.ToBase64String(ms.ToArray()); } /// /// DES解密 /// /// <param name="strSource">待解密的字串</param> /// <param name="key">32位Key值</param> /// <returns>解密后的字符串</returns> public string DESDecrypt(string strSource) { return DESDecrypt(strSource, DESKey); } public string DESDecrypt(string strSource, byte[] key) { SymmetricAlgorithm sa = Rijndael.Create(); sa.Key = key; sa.Mode = CipherMode.ECB; sa.Padding = PaddingMode.Zeros; ICryptoTransform ct = sa.CreateDecryptor(); byte[] byt = Convert.FromBase64String(strSource); MemoryStream ms = new MemoryStream(byt); CryptoStream cs = new CryptoStream(ms, ct, CryptoStreamMode.Read); StreamReader sr = new StreamReader(cs, Encoding.Unicode); return sr.ReadToEnd(); }

    01
    领券