C#DES加密解密的过程是什么呢?那么这里向你详细介绍了具体的实现过程以及方法,希望对你了解和学习C#DES加密解密有所帮助。
C# DES加密解密的完成,DES算法为暗码体系中的对称暗码体系,由IBM公司研发的对称暗码体系加密算法。其中心为密钥长度为56位,明文按64位进行分组,将分组后的明文组和56位的密钥按位代替或交流的办法构成密文组的加密办法。
C# DES加密解密的完成实例:
C# DES加密解密之称号空间 :
- usingSystem;
- usingSystem.Security.Cryptography;
- usingSystem.IO;
- usingSystem.Text;
C# DES加密解密之办法 :
- //加密办法
- publicstringEncrypt(stringpToEncrypt,stringsKey)
- {
- DESCryptoServiceProviderdes=newDESCryptoServiceProvider();
- //把字符串放到byte数组中
- //本来运用的UTF8编码,我改成Unicode编码了,不可
- byte[]inputByteArray=Encoding.Default.GetBytes(pToEncrypt);
- //byte[]inputByteArray=Encoding.Unicode.GetBytes(pToEncrypt);
C# DES加密解密之树立加密目标的密钥和偏移量
- //原文运用ASCIIEncoding.ASCII办法的GetBytes办法
- //使得输入暗码有必要输入英文文本
- des.Key=ASCIIEncoding.ASCII.GetBytes(sKey);
- des.IV=ASCIIEncoding.ASCII.GetBytes(sKey);
- MemoryStreamms=newMemoryStream();
- CryptoStreamcs=newCryptoStream(
- ms,des.CreateEncryptor(),CryptoStreamMode.Write);
- //Writethebytearrayintothecryptostream
- //(Itwillendupinthememorystream)
- cs.Write(inputByteArray,0,inputByteArray.Length);
- cs.FlushFinalBlock();
- //Getthedatabackfromthememorystream,andintoastring
- StringBuilderret=newStringBuilder();
- foreach(bytebinms.ToArray())
- {
- //Formatashex
- ret.AppendFormat("{0:X2}",b);
- }
- ret.ToString();
- returnret.ToString();
- }
C# DES加密解密之解密办法
- publicstringDecrypt(stringpToDecrypt,stringsKey)
- {
- DESCryptoServiceProviderdes=newDESCryptoServiceProvider();
- //Puttheinputstringintothebytearray
- byte[]inputByteArray=newbyte[pToDecrypt.Length/2];
- for(intx=0;x<pToDecrypt.Length/2;x++)
- {
- inti=(Convert.ToInt32(pToDecrypt.Substring(x*2,2),16));
- inputByteArray[x]=(byte)i;
- }
C# DES加密解密之树立加密目标的密钥和偏移量,此值重要,不能修正
- des.Key=ASCIIEncoding.ASCII.GetBytes(sKey);
- des.IV=ASCIIEncoding.ASCII.GetBytes(sKey);
- MemoryStreamms=newMemoryStream();
- CryptoStreamcs=newCryptoStream(ms,
- des.CreateDecryptor(),CryptoStreamMode.Write);
- //Flushthedatathroughthecryptostreamintothememorystream
- cs.Write(inputByteArray,0,inputByteArray.Length);
- cs.FlushFinalBlock();
- //Getthedecrypteddatabackfromthememorystream
- //树立StringBuild目标,
- //CreateDecrypt运用的是流目标,有必要把解密后的文本变成流目标
- StringBuilderret=newStringBuilder();
- returnSystem.Text.Encoding.Default.GetString(ms.ToArray());
- }
C# DES加密解密的实例解析就向你介绍到这儿,期望你对C# DES加密解密有所了解,对你使用C# DES加密解密有所协助。
【修改引荐】
- C# MSN Messenger的窗口的完成浅析
- C#MSN插件开发实例解析
- C#DES算法概念及特色浅析
- C#DES算法加密解密实例解析
- C#DES算法实例解析
转载请说明出处
知优网 » C#DES加密解密的完成实例浅析(c++实现des加密解密)
知优网 » C#DES加密解密的完成实例浅析(c++实现des加密解密)