一個可逆的DES和TripleDES方式加密類(downmoon原創)
using System;
using System
using System
using System
using System
namespace EncryptDownmoon
/**//// <summary>
/// EncryptSqlConn 的摘要說明
/// </summary>
public class EncryptSqlConn
public EncryptSqlConn()
if(mCSP ==null)
mCSP = SetEnc();
}
}
/**//// <summary>
/// 設置加密方式
/// </summary>
/// <returns></returns>
public EncryptSqlConn(int EnMethod)
if(EnMethod==
lngEnMethod=
}
else
lngEnMethod=
}
if(mCSP ==null)
mCSP = SetEnc();
}
}
方法#region 方法
private SymmetricAlgorithm mCSP;
private int m_lngEnMethod=
/**//// <summary>
/// 加密方式
/// </summary>
public int lngEnMethod
get
return m_lngEnMethod;
}
set
m_lngEnMethod=value;
}
}
private SymmetricAlgorithm SetEnc()
if(lngEnMethod==
return new DESCryptoServiceProvider();
}
else
return new TripleDESCryptoServiceProvider();
}
//測試鍵值
private string genKeyValue
get
mCSP
return Convert
}
}
//測試IV值
private string genIVValue
get
mCSP
return Convert
}
}
/**//// <summary>
/// 加密字串
/// </summary>
/// <param name=
/// <returns></returns>
public string EncryptString(string Value)
ICryptoTransform ct;
MemoryStream ms;
CryptoStream cs;
byte[] byt;
ct = mCSP
//ct = mCSP
byt = Encoding
ms = new MemoryStream();
cs = new CryptoStream(ms
cs
cs
cs
return Convert
}
/**//// <summary>
/// 解密字串
/// </summary>
/// <param name=
/// <returns></returns>
public string DecryptString(string Value)
ICryptoTransform ct;
MemoryStream ms;
CryptoStream cs;
byte[] byt;
ct = mCSP
//ct = mCSP
byt = Convert
ms = new MemoryStream();
cs = new CryptoStream(ms
cs
cs
cs
return Encoding
}
#endregion
}
}
From:http://tw.wingwit.com/Article/program/net/201311/12830.html