发一个加密的方法
//声明加密字符生成的随机数的位数public const int LENGTH = 32;
//声明加密字符前后的分隔长度
public const int LEN = 4;
///方法作用:根据参数对其加密
///参数:
/// string strEncrypt;欲加密的字符
///返回结果:加密后的字符
public static byte[] SourceEncrypt(string strEncrypt)
{
string source = Encrypt(strEncrypt);
//first
string first = Encrypt(source.Substring(0,LEN));
//second
string second = Encrypt(source.Substring(LEN-1,source.Length-LEN));
//third
string third = Encrypt(source.Substring(source.Length-LEN,LEN));
//four
byte[] Random = new byte[LENGTH];
RNGCryptoServiceProvider rng = new RNGCryptoServiceProvider();
rng.GetNonZeroBytes(Random);
string four = Encrypt(System.Text.Encoding.ASCII.GetString(Random));
string all = first+second+third+four;
return System.Text.Encoding.ASCII.GetBytes(all);
} // end SourceEncrypt
///方法作用:对参数进行加密
///参数:
/// string strEncrypt:欲加密的字符
/// 返回结果:加密后的字符
public static string Encrypt(string strEncrypt)
{
SHA256Managed sha = new SHA256Managed();
byte[] VALUE = sha.ComputeHash(System.Text.Encoding.ASCII.GetBytes(strEncrypt));
return System.Text.Encoding.ASCII.GetString(VALUE);
} // end Encrypt
///方法作用:对参数进行比较
///参数:
/// string strSource:原字符
/// string strObject:目标字符
/// 返回结果:bool是否相等
public static bool CompareEncrypt(byte[] strSource,string strobject)
{
bool result = true;
byte[] strObject = SourceEncrypt(strobject);
//strObject = SourceEncrypt(strObject);
if((strSource==null) || (strObject==null) || (strSource.Length != strObject.Length))
result = false;
else
{
//strSource = strSource.Substring(0,strSource.Length-LENGTH);
补充:asp教程,安全加密