最新下载
热门教程
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
发一个加密的方法
时间:2022-06-30 09:18:09 编辑:袖梨 来源:一聚教程网
//声明加密字符生成的随机数的位数
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);
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);
相关文章
- 无期迷途主线前瞻直播总结 无期迷途主线前瞻直播内容介绍 11-22
- 以下哪种非遗技艺是用针在纸上绣画 蚂蚁新村11月21日答案 11-22
- 江南百景图听风塔怎么样 11-22
- 原神恰斯卡圣遗物怎么搭配 11-22
- 2024年霸王茶姬11月22日口令是什么 2024.11.22霸王茶姬口令介绍 11-22
- 光遇11.21季节蜡烛在哪里 光遇11月21日季节蜡烛位置攻略 11-22