日本综合一区二区|亚洲中文天堂综合|日韩欧美自拍一区|男女精品天堂一区|欧美自拍第6页亚洲成人精品一区|亚洲黄色天堂一区二区成人|超碰91偷拍第一页|日韩av夜夜嗨中文字幕|久久蜜综合视频官网|精美人妻一区二区三区

RELATEED CONSULTING
相關咨詢
選擇下列產(chǎn)品馬上在線溝通
服務時間:8:30-17:00
你可能遇到了下面的問題
關閉右側工具欄

新聞中心

這里有您想知道的互聯(lián)網(wǎng)營銷解決方案
C#DES加密解密的實現(xiàn)實例淺析

C# DES加密解密的實現(xiàn),DES算法為密碼體制中的對稱密碼體制,由IBM公司研制的對稱密碼體制加密算法。其核心為密鑰長度為56位,明文按64位進行分組,將分組后的明文組和56位的密鑰按位替代或交換的方法形成密文組的加密方法。

C# DES加密解密的實現(xiàn)實例:

C# DES加密解密之名稱空間  :

 
 
 
  1. using  System;    
  2. using  System.Security.Cryptography;    
  3. using  System.IO;    
  4. using  System.Text;   

C# DES加密解密之方法 :

 
 
 
  1. //加密方法    
  2. publicstring  Encrypt(string  pToEncrypt,  string  sKey)    
  3. {    
  4.  DESCryptoServiceProvider  des  =  new  DESCryptoServiceProvider();    
  5.  //把字符串放到byte數(shù)組中    
  6.   //原來使用的UTF8編碼,我改成Unicode編碼了,不行    
  7.  byte[]  inputByteArray  =  Encoding.Default.GetBytes(pToEncrypt);    
  8.  //byte[]  inputByteArray=Encoding.Unicode.GetBytes(pToEncrypt);  

C# DES加密解密之建立加密對象的密鑰和偏移量 

 
 
 
  1.  //原文使用ASCIIEncoding.ASCII方法的GetBytes方法    
  2.  //使得輸入密碼必須輸入英文文本    
  3.  des.Key  =  ASCIIEncoding.ASCII.GetBytes(sKey);    
  4.  des.IV  =  ASCIIEncoding.ASCII.GetBytes(sKey);    
  5.  MemoryStream  ms  =  new  MemoryStream();    
  6.  CryptoStream  cs  =  new  CryptoStream(  
  7. ms,  des.CreateEncryptor(),CryptoStreamMode.Write);    
  8.  //Write  the  byte  array  into  the  crypto  stream    
  9.  //(It  will  end  up  in  the  memory  stream)    
  10.  cs.Write(inputByteArray,  0,  inputByteArray.Length);    
  11.  cs.FlushFinalBlock();    
  12.  //Get  the  data  back  from  the  memory  stream,  and  into  a  string    
  13.  StringBuilder  ret  =  new  StringBuilder();    
  14.  foreach(byte  b  in  ms.ToArray())    
  15.    {    
  16.    //Format  as  hex    
  17.    ret.AppendFormat("{0:X2}",  b);    
  18.    }    
  19.  ret.ToString();    
  20.  return  ret.ToString();    
  21. }   

C# DES加密解密之解密方法 

 
 
 
  1. publicstring  Decrypt(string  pToDecrypt,  string  sKey)    
  2. {    
  3.  DESCryptoServiceProvider  des  =  new  DESCryptoServiceProvider();    
  4.  
  5.  //Put  the  input  string  into  the  byte  array    
  6.  byte[]  inputByteArray  =  new  byte[pToDecrypt.Length  /  2];    
  7.  for(int  x  =  0;  x  <  pToDecrypt.Length  /  2;  x++)    
  8.  {    
  9.  int  i  =  (Convert.ToInt32(pToDecrypt.Substring(x  *  2,  2),  16));    
  10. inputByteArray[x]  =  (byte)i;    
  11.  }   

C# DES加密解密之建立加密對象的密鑰和偏移量,此值重要,不能修改 

 
 
 
  1.  des.Key  =  ASCIIEncoding.ASCII.GetBytes(sKey);    
  2.  des.IV  =  ASCIIEncoding.ASCII.GetBytes(sKey);    
  3.  MemoryStream  ms  =  new  MemoryStream();    
  4.  CryptoStream  cs  =  new  CryptoStream(ms,    
  5. des.CreateDecryptor(),CryptoStreamMode.Write);    
  6.  //Flush  the  data  through  the  crypto  stream  into  the  memory  stream    
  7.  cs.Write(inputByteArray,  0,  inputByteArray.Length);    
  8.  cs.FlushFinalBlock();    
  9.  
  10.  //Get  the  decrypted  data  back  from  the  memory  stream    
  11.  //建立StringBuild對象,  
  12. //CreateDecrypt使用的是流對象,必須把解密后的文本變成流對象    
  13.  StringBuilder  ret  =  new  StringBuilder();    
  14.      
  15.  return  System.Text.Encoding.Default.GetString(ms.ToArray());    
  16. }  

C# DES加密解密的實例解析就向你介紹到這里,希望你對C# DES加密解密有所了解,對你應用C# DES加密解密有所幫助。

【編輯推薦】

  1. C# MSN Messenger的窗口的實現(xiàn)淺析
  2. C#MSN插件開發(fā)實例解析
  3. C#DES算法概念及特點淺析
  4. C#DES算法加密解密實例解析
  5. C#DES算法實例解析

網(wǎng)站題目:C#DES加密解密的實現(xiàn)實例淺析
網(wǎng)站地址:http://www.dlmjj.cn/article/cdjgspd.html