惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

L
LINUX DO - 最新话题
C
Cyber Attacks, Cyber Crime and Cyber Security
G
GRAHAM CLULEY
T
Tenable Blog
T
Threatpost
C
CXSECURITY Database RSS Feed - CXSecurity.com
I
Intezer
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
D
Darknet – Hacking Tools, Hacker News & Cyber Security
K
Kaspersky official blog
Security Latest
Security Latest
P
Privacy & Cybersecurity Law Blog
Google Online Security Blog
Google Online Security Blog
SecWiki News
SecWiki News
P
Palo Alto Networks Blog
TaoSecurity Blog
TaoSecurity Blog
Webroot Blog
Webroot Blog
Spread Privacy
Spread Privacy
O
OpenAI News
The Last Watchdog
The Last Watchdog
P
Proofpoint News Feed
C
Check Point Blog
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
人人都是产品经理
人人都是产品经理
S
Security @ Cisco Blogs
Scott Helme
Scott Helme
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
月光博客
月光博客
S
Securelist
酷 壳 – CoolShell
酷 壳 – CoolShell
V
V2EX
T
Troy Hunt's Blog
W
WeLiveSecurity
GbyAI
GbyAI
N
News | PayPal Newsroom
Y
Y Combinator Blog
C
Cisco Blogs
H
Help Net Security
The GitHub Blog
The GitHub Blog
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
博客园 - 【当耐特】
Jina AI
Jina AI
MongoDB | Blog
MongoDB | Blog
P
Proofpoint News Feed
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
云风的 BLOG
云风的 BLOG
小众软件
小众软件
N
News and Events Feed by Topic

博客园 - edobnet

phonegap 开发初探 阿里软件接口开发基础(淘宝网) C# SQL 2005自动备份文件删除 短信猫与中国移动CMPP2。0收发短信实例 通过OSQL命令执行SQL SERVER批SQL 针对sql 2005优化的高性能分页存储过程 .net framework 2.0以上修改config配制更容易 - edobnet LinQ操作汇总(From CSharpSamples) 远程注册表读取,与多线程池的应用. 使用JAVASCRIPT控制,IFAME的内容,从而使用投票点击等功能 ADSL自动断拨号类 类拟EXCEL表格锁定的功能的实现! - edobnet - 博客园 线程,线程数控制! sql Server 2000 分区视图的运用 利用.Net 线程池提高应用程序性能. google 中国编程大赛测试题,及自己的解答 触发器在增量同步数据的运用. 进程服务编写,与启动停止控制 js异步XMLhttpPost,并带有,等待显示,防正,XMLhttpPost请求时间过来,而使浏览器死掉! - edobnet - 博客园
.net C# ADC接口中DES加密算法
edobnet · 2010-08-16 · via 博客园 - edobnet

原文档加密算法描述如下:

1.1      消息安全性

Des加密保证消息的不可阅读性。

对消息的加密算法:Base64(DES(MD5(消息体) + 消息体))

消息采用的DES加密算法规则如下:

1.密钥是一个长度16、由16进制字符组成的字符串,如:1234567890ABCDEF

使用时,相临的两位理解为一个16进制数的明文,然后转换为实际使用的8位密钥

2. 待加密数据按照PKCS5规则进行补位。(缺7位补70x07,缺6位则补60x06,以次类推,如果正好8位,也需要补80x08

3. 实际加密模式选择DES-ECB

4. 经过DES加密后的数据必须通过Base64编码转换为明文的字符串

华为提示java的jar包,但.net 方面是没有方法,网上查询了很多,des方法有很多,加密结果不一样,经常仔细阅读加密算法,终于实现在,提供给大家

代码

using System;
using System.Text;
using System.ComponentModel;
using System.Collections;
using System.Security;
using System.Security.Cryptography;
using System.Diagnostics;
using System.IO;
namespace AdcLib.Util
{
    
///   <summary> 
    
///   Class1   的摘要说明。 
    
///   </summary> 
    public class SecurityUtil     //加密解密类 
    {///   <summary> 
        
///   3des加密字符串 
        
///   </summary> 
        
///   <param   name= "a_strString "> 要加密的字符串 </param> 
        
///   <param   name= "a_strKey "> 密钥 </param> 
        
///   <returns> 加密后并经base64编码的字符串 </returns> 
        
///   <remarks> 静态方法,采用默认ascii编码 </remarks> 
        public static string EncryptDES(string a_strString, string a_strKey)
        {
            DESCryptoServiceProvider DES 
= new DESCryptoServiceProvider();
            
            
//TripleDESCryptoServiceProvider DES = new TripleDESCryptoServiceProvider();
            
//MD5CryptoServiceProvider hashMD5 = new MD5CryptoServiceProvider();
           byte[] b = strToToHexByte(a_strKey);

            DES.Key 

= b;
           
// DES.IV = b;
          
//  DES.Key = b;//ASCIIEncoding.ASCII.GetBytes(a_strKey);//hashMD5.ComputeHash(ASCIIEncoding.ASCII.GetBytes(a_strKey));
            DES.Mode = CipherMode.ECB;
            DES.Padding 
= PaddingMode.PKCS7;
          

          
            ICryptoTransform DESEncrypt 

= DES.CreateEncryptor();byte[] Buffer = ASCIIEncoding.UTF8.GetBytes(a_strString);
            
return Convert.ToBase64String(DESEncrypt.TransformFinalBlock(Buffer, 0, Buffer.Length));
        }
//end   method 
private static byte[] strToToHexByte(string hexString)
        {
            
byte[] returnBytes = new byte[hexString.Length / 2];
            
for (int i = 0; i < returnBytes.Length; i++)
                returnBytes[i] 
= Convert.ToByte(hexString.Substring(i * 22),16);
            
return returnBytes;
        }
///   <summary> 
        
///   3des解密字符串 
        
///   </summary> 
        
///   <param   name= "a_strString "> 要解密的字符串 </param> 
        
///   <param   name= "a_strKey "> 密钥 </param> 
        
///   <returns> 解密后的字符串 </returns> 
        
///   <exception   cref= " "> 密钥错误 </exception> 
        
///   <remarks> 静态方法,采用默认ascii编码 </remarks> 
        public static string DecryptDES(string a_strString, string a_strKey)
        {
            DESCryptoServiceProvider DES 
= new DESCryptoServiceProvider();

            DES.Key 

= strToToHexByte(a_strKey);
            DES.Mode 
= CipherMode.ECB;
            DES.Padding 
= PaddingMode.PKCS7;

            ICryptoTransform DESDecrypt 

= DES.CreateDecryptor();string result = " ";
            
try
            {
                
byte[] Buffer = Convert.FromBase64String(a_strString);
                result 
= ASCIIEncoding.UTF8.GetString(DESDecrypt.TransformFinalBlock(Buffer, 0, Buffer.Length));
            }
            
catch (Exception e)
            {
throw (new Exception("Invalid   Key   or   input   string   is   not   a   valid   base64   string ", e));
            }
return result;
        }
//end   method 

    
        
/// <summary>
        
/// MD5
        
/// </summary>
        
/// <param name="data"></param>
        
/// <returns></returns>
        public static string MD5(string data)
        {
            System.Security.Cryptography.MD5CryptoServiceProvider md5 
= new System.Security.Cryptography.MD5CryptoServiceProvider();
            
return BitConverter.ToString(md5.ComputeHash(Encoding.UTF8.GetBytes(data))).Replace("-""").ToLower();
        }

    }
}