设为首页 加入收藏 网站搜索 繁體中文 中国建站网 — 站长资源分享平台

DotNet中用到的加密算法总结

来源:网络收集 作者:佚名 时间:2007-04-25 23:37:29

  1public class CryptUtil
  2    {
  3        public static string DecryptString(string input)
  4        {
  5            if (input.Equals(string.Empty))
  6            {
  7                return input;
  8            }
  9
 10            byte[] byKey = {0x63, 0x68, 0x65, 0x6E, 0x79, 0x75, 0x61, 0x6E};
 11            byte[] IV = {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10};
 12            byte[] inputByteArray = new Byte[input.Length];
 13            DESCryptoServiceProvider des = new DESCryptoServiceProvider();
 14            inputByteArray = Convert.FromBase64String(input);
 15            MemoryStream ms = new MemoryStream();
 16            CryptoStream cs = new CryptoStream(ms, des.CreateDecryptor(byKey, IV), CryptoStreamMode.Write);
 17            cs.Write(inputByteArray, 0, inputByteArray.Length);
 18            cs.FlushFinalBlock();
 19            Encoding encoding = new UTF8Encoding();
 20            return encoding.GetString(ms.ToArray());
 21        }
 22
 23        public static string EncryptString(string input)
 24        {
 25            if (input.Equals(string.Empty))
 26            {
 27                return input;
 28            }
 29
 30            byte[] byKey = {0x63, 0x68, 0x65, 0x6E, 0x79, 0x75, 0x61, 0x6E};
 31            byte[] IV = {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10};
 32            DESCryptoServiceProvider des = new DESCryptoServiceProvider();
 33            byte[] inputByteArray = Encoding.UTF8.GetBytes(input);
 34            MemoryStream ms = new MemoryStream();
 35            CryptoStream cs = new CryptoStream(ms, des.CreateEncryptor(byKey, IV), CryptoStreamMode.Write);
 36            cs.Write(inputByteArray, 0, inputByteArray.Length);
 37            cs.FlushFinalBlock();
 38            return Convert.ToBase64String(ms.ToArray());
 39        }
 40        /**//// <summary>
 41        /// DES + Base64 加密
 42        /// </summary>
 43        /// <param name="input">明文字符串</param>
 44        /// <returns>已加密字符串</returns>
 45        public static string DesBase64Encrypt(string input)
 46        {
 47            System.Security.Cryptography.DES des = System.Security.Cryptography.DES.Create();
 48            des.Mode = System.Security.Cryptography.CipherMode.ECB;
 49            ICryptoTransform ct;
 50            MemoryStream ms;

[1] [2] [3] [4] [5] [6]  下一页

Tags:

  • 好的评价 如果您觉得好,就请您
      0%(0)
  • 差的评价 如果您觉得差,就请您
      0%(0)
  • 相关文章
    广告赞助

    文章随便看看 设计素材 建站学院 网页模板 视频教程

    网友评论

    共有 0 位网友发表了评论,得分 0 分,平均 0 分    查看完整评论

    用户名: 查看更多评论

    分 值:100分 85分 70分 55分 40分 25分 10分 1分

    内 容:

             通知管理员 验证码: