{ //定义DES的Provider
DESCryptoServiceProvider desprovider =
new DESCryptoServiceProvider();
//转换解密的字符串为二进制
byte[] buffer = Convert.FromBase64String(valueString);
//定义内存流
MemoryStream memoryStream = new MemoryStream();
//定义加密流
CryptoStream cryptoStream = new CryptoStream(memoryStream,
desprovider.CreateEncryptor(Key64,IV64),
CryptoStreamMode.Read);
//定义读IO流
StreamReader readerStream = new StreamReader(cryptoStream);
//返回解密后的字符串
return(readerStream.ReadToEnd());
}
return(null);
}
public static String EncryptTripleDES(String valueString)
{
if(valueString != "")
{ //定义TripleDES的Provider
TripleDESCryptoServiceProvider triprovider =
new TripleDESCryptoServiceProvider();
//定义内存流
MemoryStream memoryStream = new MemoryStream();
//定义加密流
CryptoStream cryptoStream = new CryptoStream(memoryStream,
triprovider.CreateEncryptor(Key192,IV192),
CryptoStreamMode.Write);
//定义写IO流
StreamWriter writerStream = new StreamWriter(cryptoStream);
//写入加密后的字符流
writerStream.Write(valueString);
writerStream.Flush();
cryptoStream.FlushFinalBlock();
memoryStream.Flush();
//返回加密后的字符串
return(Convert.ToBase64String(memoryStream.GetBuffer(),0,
(int)memoryStream.Length));
}
return(null);
}
public static String DecryptTripleDES(String valueString)
{
if(valueString != "")
{ //定义TripleDES的Provider
TripleDESCryptoServiceProvider triprovider =
new TripleDESCryptoServiceProvider();
//转换解密的字符串为二进制
byte[] buffer = Convert.FromBase64String(valueString);
//定义内存流
MemoryStream memoryStream = new MemoryStream();
//定义加密流
文章来源于领测软件测试网 https://www.ltesting.net/