找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
查看: 3072|回复: 0
收起左侧

des加密与解密C#源码分享

[复制链接]
ID:458836 发表于 2019-1-30 11:42 | 显示全部楼层 |阅读模式
c#des加密与解密的相关介绍:
DES全称为Data Encryption Standard,即数据加密标准,是一种使用密钥加密的块算法,1977年被美国家标准局确定为联邦资料处理标准(FIPS),并授权在非密级通信中使用,随后该算法在国际上广泛流传开来。需要注意的是,在某些文献中,作为算法的DES称为数据加密算法(Data Encryption Algorithm,DEA),已与作为标准的DES区分开来。


0.png

c#源码:
  1. public static string 加密(string input, string sKey)//来自wqdqdq
  2.         {
  3.             byte[] data = Encoding.UTF8.GetBytes(input);
  4.             using (DESCryptoServiceProvider des = new DESCryptoServiceProvider())
  5.             {
  6.                 des.Key = ASCIIEncoding.ASCII.GetBytes(sKey);
  7.                 des.IV = ASCIIEncoding.ASCII.GetBytes(sKey);
  8.                 ICryptoTransform desencrypt = des.CreateEncryptor();
  9.                 byte[] result = desencrypt.TransformFinalBlock(data, 0, data.Length);
  10.                 return BitConverter.ToString(result);
  11.             }
  12.         }
  13.         public static string 解密(string input, string sKey)
  14.         {
  15.             try
  16.             {
  17.                 string[] sInput = input.Split("-".ToCharArray());
  18.                 byte[] data = new byte[sInput.Length];
  19.                 for (int i = 0; i < sInput.Length; i++)
  20.                 {
  21.                     data[i] = byte.Parse(sInput[i], NumberStyles.HexNumber);
  22.                 }
  23.                 using (DESCryptoServiceProvider des = new DESCryptoServiceProvider())
  24.                 {
  25.                     des.Key = ASCIIEncoding.ASCII.GetBytes(sKey);
  26.                     des.IV = ASCIIEncoding.ASCII.GetBytes(sKey);
  27.                     ICryptoTransform desencrypt = des.CreateDecryptor();
  28.                     byte[] result = desencrypt.TransformFinalBlock(data, 0, data.Length);
  29.                     Console.Write(result); return Encoding.UTF8.GetString(result);
  30.                 }
  31.             }
  32.             catch { byte[] apk = System.Text.Encoding.Default.GetBytes("错误"); return Encoding.UTF8.GetString(apk); }
复制代码

全部资料51hei下载地址:
des加密.zip (55.52 KB, 下载次数: 10)

评分

参与人数 1黑币 +50 收起 理由
admin + 50 共享资料的黑币奖励!

查看全部评分

回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

手机版|小黑屋|51黑电子论坛 |51黑电子论坛6群 QQ 管理员QQ:125739409;技术交流QQ群281945664

Powered by 单片机教程网

快速回复 返回顶部 返回列表