当前位置:编程学习 > 网站相关 >>

DES加密/解密的应用

加解密
using System.Security.Cryptography;
 
private static byte[] DESKey = new byte[] {11,23,93,102,72,41,18,12};
private static byte[] DESIV = new byte[] {75,158,46,97,78,57,17,36};
//加密函數:
public static string Encode(string Encode_String)
{
DESCryptoserviceProvider objDES = new DESCryptoserviceProvider();
MemoryStream objMemoryStream = new MemoryStream();
Cryptostream objCryptostream = new Cryptostream
(objMemoryStream,objDES.CreateEncryptor(DESKey,DESIV),CryptostreamMode.Write);
StreamWriter objStreamWriter = new StreamWriter(objCryptostream);
objStreamWriter.Write(Encode_String);
objStreamWriter.Flush();
objCryptostream.FlushFinalBlock();
objMemoryStream.Flush();
return Convert.ToBase64String(objMemoryStream.GetBuffer(), 0, (int)
objMemoryStream.Length);
}
 
//解密函數 www.zzzyk.com
public static string Decode(string Encode_String)
{
DESCryptoserviceProvider objDES = new DESCryptoserviceProvider();
byte[] Input = Convert.FromBase64String(Encode_String);
MemoryStream objMemoryStream = new MemoryStream(Input);
Cryptostream objCryptostream = new Cryptostream
(objMemoryStream,objDES.CreateDecryptor(DESKey,DESIV),CryptostreamMode.Read);
StreamReader objStreamReader = new StreamReader(objCryptostream);
return objStreamReader.ReadToEnd();
}
 
补充:综合编程 , 安全编程 ,
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,