在csdn找了个加密解密的方法 ,但是不知道咋用啊 ,谁给教教?

jiery666 2015-05-27 09:36:59
http://bbs.csdn.net/topics/360136430
asp加密
<%
Dim ClearPassKey="" ‘512位的密匙"
Signature="aaaaaaa" ‘干扰码
Wise=False
'密码提取初始位置
Initial=14
'密码提取间隔值
Quantity=5

ClearKeyLength=512
'特征码补位,检测系统特征码长度,是否能够需要加密的字符串进行异或操作,要求长度相同
Function strFill(AccountPass)
Dim I
IF Len(AccountPass) > Len(Signature) Then
'FillLen = Len(AccountPass) - Len(Signature)
For I = 1 To Len(AccountPass) \ Len(Signature) + 1
Signature = Signature & Signature
Next
Signature = Mid(Signature,1,Len(AccountPass))
Else
Signature = Mid(Signature,1,Len(AccountPass))
End IF
strFill = Signature
End Function


'从密匙明文中提取密匙
Function Distill(Length,Wise,Quantity,Initial,KeyLength)
'Length 用户密码称度
'ClearPassKey 密码明文串
'Wise 提取方式 {True:Quantity固定间隔值 False:Quantity递增倍数}
'Initial 初始位置
'KeyLength 密码明文串长度
'strLength 根据用户密码长度及截取方式后共需要多少个字符,如果字符串长度超过密码明文长度就会出错
Dim strLength,I,chrDistill,strDistill,Degree,chrLenght
IF Wise = True Then
strLength = Initial+(Length-1)*(Quantity+1)
IF strLength <= KeyLength Then
For I = 1 To Length
IF I=1 Then
chrDistill = Mid(ClearPassKey,Initial,1)
'第一个字符提取 从密匙串是起始位置提取一个
Else
chrDistill = Mid(ClearPassKey,(Initial+(Quantity+1)*(I-1)),1)
'第二个字符提取 从密匙串的起始位置+间隔字符数+1的位置
End IF
strDistill = strDistill & chrDistill
Next
End IF
Else
For Degree = 1 To Length
IF Degree = 1 Then
strLength = Initial
Else
strLength = strLength+Quantity*(Degree-1)+1
End IF
Next
IF strLength <= KeyLength Then
For I = 1 To Length
IF I=1 Then
chrLenght = Initial
chrDistill = Mid(ClearPassKey,chrLenght,1)
'Response.Write chrLenght&"|"&chrDistill&"<br>"
Else
chrLenght = chrLenght+Quantity*(I-1)+1
chrDistill = Mid(ClearPassKey,chrLenght,1)
'Response.Write chrLenght&"|"&chrDistill&"<br>"
'第二个字符提取 从密匙串的起始位置+(间隔字符数+1的位置)*(循环次数-1)+1 {第一次循环不用递增,只要从起始位置开始取即可}
End IF
strDistill = strDistill & chrDistill
Next
End IF
End IF
Distill = strDistill
End Function



Function EnCrypt(DistillKey,Signature,AccountPass)
Dim I,chrDistillKey,chrAccountPass,chrEnCryptPass,strEnCryptPass,chrSignature,chrEnCrypt,strEnCrypt
For I = 1 to Len(AccountPass)
'for 循环,从用户输入的密码串中,第一个字符开始到字符串结束,每个字符都进行一次循环内部的操作
chrDistillKey = Asc(Mid(DistillKey,I,1))
'mid(g_Key,I,1) 从密匙文中从第I个字符开始,取出一个字符,Asc()获取这个字符的ASCII码值
chrAccountPass = Asc(Mid(AccountPass,I,1))
'mid(strCryptThis,I,1) 从系统密匙中的第I个字符开始,取第一个字符,Asc()获取这个字符的ASCII码值
chrEnCryptPass = chrDistillKey Xor chrAccountPass
strEnCryptPass = strEnCryptPass & Chr(chrEnCryptPass)
Next
For I = 1 to Len(Signature)
'for 循环,从用户输入的密码串中,第一个字符开始到字符串结束,每个字符都进行一次循环内部的操作
chrEnCryptPass = Asc(Mid(strEnCryptPass,I,1))
'mid(g_Key,I,1) 从密匙文中从第I个字符开始,取出一个字符,Asc()获取这个字符的ASCII码值
chrSignature = Asc(Mid(Signature,I,1))
'mid(strCryptThis,I,1) 从系统密匙中的第I个字符开始,取第一个字符,Asc()获取这个字符的ASCII码值
chrEnCrypt = chrEnCryptPass Xor chrSignature
strEnCrypt = strEnCrypt & Chr(chrEnCrypt)
Next
EnCrypt = strEnCrypt
End Function
%>


c#中解密
private readonly string Signature = "aaaaaaa" //必须与上面对应;

private const string ClearPassKey = @""; //512位密匙,必须与上面对应

/// <summary>
/// 取特征码长度要一至
/// </summary>
/// <param name="lenth"></param>
/// <returns></returns>
public char[] strFill(int lenth)
{
string signature=Signature;
if (lenth > signature.Length)
{
for (int i = 1; i <= (lenth / signature.Length + 1); i++)
{
signature += Signature;
}
signature += Signature;
}
signature = signature.Substring(0, lenth);
return signature.ToCharArray();
}
/// <summary>
/// 取密匙
/// </summary>
/// <param name="Length"></param>
/// <returns></returns>
public char[] Distill(int Length)
{
string chrDistill="", strDistill="";
for (int i = 0; i < Length; i++)
{
chrDistill = ClearPassKey.Substring(Length + i, 1);
strDistill = strDistill + chrDistill;
}
return strDistill.ToCharArray();
}
/// <summary>
/// 解密
/// </summary>
/// <param name="PassWord"></param>
/// <returns></returns>
public string DeCrypt(string PassWord)
{

int chrDistill = 0, chrSignature = 0, chrDeCryptPass = 0, chrPassWord = 0, chrAdd = 0, chrDeCrypt=0;


string strDeCryptPass="",strDeCrypt="";

string[] snum = Regex.Split(PassWord, "[A-Z]", RegexOptions.IgnoreCase);
string pat = @"[A-Z]";
string[] chr = new string[snum.Length];
Regex r = new Regex(pat, RegexOptions.IgnoreCase);
MatchCollection m = r.Matches(PassWord);
for (int i = 0; i < m.Count; i++)
{
chr[i + 1] = m[i].Value;
}
int len = chr.Length - 1;
char[] DistillKey = Distill(len);
char[] Signature = strFill(len);
for (int i = 0; i < Signature.Length; i++)
{
//chrDistill = Convert.ToInt32((char)DistillKey.Substring(i, 1));
//chrSignature = Convert.ToInt32((char)Signature.Substring(i, 1));
chrDistill = Convert.ToInt32(DistillKey[i]);
chrSignature = Convert.ToInt32(Signature[i]);
chrDeCryptPass=chrDistill^chrSignature;
strDeCryptPass = strDeCryptPass + Convert.ToChar(chrDeCryptPass);
}
for (int i = 1; i <= len; i++)
{
chrDeCryptPass = Convert.ToInt32(strDeCryptPass.ToCharArray()[i-1]);
chrPassWord = Convert.ToInt32(chr[i].ToCharArray()[0]);
chrAdd=0;
if (snum[i] != "")
chrAdd = Convert.ToInt32(snum[i]);
chrPassWord = chrPassWord - chrAdd;
chrDeCrypt = chrDeCryptPass ^ chrPassWord;
strDeCrypt = strDeCrypt + Convert.ToChar(chrDeCrypt);
}
return strDeCrypt;
}


但是对于以上两段方法 我不知道咋调用 ?
谁给举个例子?
...全文
212 回复 打赏 收藏 转发到动态 举报
写回复
用AI写文章
回复
切换为时间正序
请发表友善的回复…
发表回复

87,907

社区成员

发帖
与我相关
我的任务
社区描述
Web 开发 JavaScript
社区管理员
  • JavaScript
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧