有用过ET99(加密UKEY)的请进,要请教了!

qqpass2009 2009-02-22 01:34:34
想做一个用UKEY登录的窗口,看了自带的例子(两个前台ASPX面页,一个主要是判断UKEY是否存在和输入密码等,别一个是验证代码),能明白,但我想把这两个ASPX面页写成一个前台ASPX面页,一个后到ASPX.CS面页!

我后来写的,在本机测试通过,但在别的机子上测试就通过不了,找不到方法!!


例子:
1、logon.aspx

<%@ Page Language="c#" EnableSessionState=true %>

<%
//here we generate a random number
Random randomGenerator = new Random(DateTime.Now.Millisecond);

String RandData = "";
for(int i=0; i<20; i++)
RandData += Convert.ToChar(randomGenerator.Next(97,122));

Session["Message"] = RandData;
%>

<HTML>
<HEAD>
<TITLE>Logon - ET99 Test [ASP.NET]</TITLE>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1">
<STYLE TYPE="text/css">
<!--
@import "test.css";
-->
</STYLE>
<script language=VBScript>
Dim FirstDigest
Dim Digest
Digest= "01234567890123456"

dim bErr

sub ShowErr(Msg)
bErr = true
MsgBox Msg
' Document.Writeln "<FONT COLOR='#FF0000'>"
' Document.Writeln "<P> </P><P> </P><P> </P><P ALIGN='CENTER'><B>ERROR:</B>"
' Document.Writeln "<P> </P><P ALIGN='CENTER'>"
' Document.Writeln Msg
' Document.Writeln " failed, and returns 0x" & hex(Err.number) & ".<br>"
' Document.Writeln "<P> </P><P> </P><P> </P>"
' Document.Writeln "</FONT>"
End Sub

function Validate()
Digest = "01234567890123456"
On Error Resume Next
Dim TheForm
Set TheForm = Document.forms("ValidForm")
If Len(TheForm.UserPIN.Value) <> 16 Then
MsgBox "PIN empty or user pin length is not 16!"
Validate = FALSE
Exit Function
End If
If Len(TheForm.TokenPid.Value) <> 8 Then
MsgBox "Input pid is wrong!"
Validate = FALSE
Exit Function
End If

bErr = false

chPid =TheForm.TokenPid.Value
'Let detecte whether the ET99 Safe Active Control loaded.
'If we call any method and the Err.number be se13:19 2006-5-22t to &H1B6, it
'means the ET99 Safe Active Control had not be loaded.
tokencount = ET99.FindToken ( chPid )
'tokencount = ET99.FindToken (TheForm.TokenPid.Value)
If Err Then

ShowErr "Not found ET99"
'scanf(message,%lx,Err.code)
ShowErr Digest
Validate = false
Exit function
Else
ET99.OpenToken chPid,1
'ET99.OpenToken TheForm.TokenPid.Value,1

If Err then
ShowErr "Open ET99 failed."
Validate = false
Exit function
End if


'ET99.VerifyPIN CInt(TheForm.Identity.Value), CStr(TheForm.UserPIN.Value)
ET99.VerifyPIN 0, TheForm.UserPIN.Value
If Err Then
ShowErr "Verify User PIN Failure!!!"
Validate = false
ET99.CloseToken
Exit function
End If

'you can use this function to get SN
'GetSN
dim results
results = "01234567890123456"
results = ET99.GetSN
If Err Then
ShowErr "Get SN fail!"
ET99.CloseToken
Exit function
End If

'Do HASH-MD5-HMAC compute.
If Not bErr Then
Digest = ET99.MD5HMAC (1, "<%=Session["Message"].ToString()%>", 20)
If Err Then
ShowErr "HashToken compute"
Validate = false
ET99.CloseToken
Exit function
End If


DigestID.innerHTML = "<input type='hidden' name='Digest' Value='" & Digest & "'>"
snID.innerHTML = "<input type='hidden' name='SN_SERAL' Value='" & results & "'>"
End If
End If
ET99.CloseToken
End function
</script>

</HEAD>
<BODY>

<OBJECT classid=clsid:e6bd6993-164f-4277-ae97-5eb4bab56443 id=ET99 name = ET99 STYLE="LEFT: 0px; TOP: 0px" width=0 height=0></OBJECT>

<H1 ALIGN="center">ET99 Active Control<BR>Demo Program for C#</H1>
<TABLE WIDTH="600" BORDER="0" ALIGN="center">
<TR>
<TD>
<P ALIGN="CENTER">Welcome to ET99 Active Control demonstration program for C#.</P>


<SCRIPT id=clientEventHandlersVBS language=vbscript>
<!--
'Now you had get the result of HASH compute and the random data
' use to HASH compute. You should post these data to server and
' do verify operation.
Document.Writeln "<P> </P><P ALIGN='CENTER'>To logon, you must input Token Pid and your PIN.</P>"
Document.Writeln "<P> </P><P> </P></TD></TR><TR><TD>"
Document.Writeln "<FORM id=ValidForm METHOD='post' ACTION='verify.aspx' onsubmit='return Validate();' language='jscript'>"

'Post the result of HASH compute by ET99 can use by server.

Document.Writeln "<span id=DigestID></span>"
Document.Writeln "<span id=snID></span>"
'Document.Writeln "<input type='hidden' name='Digest' Value='" & Digest & "'>"

'Create a table and let user input the PIN.
Document.Writeln "<TABLE WIDTH='250' BORDER='1' ALIGN='center' CELLSPACING='0' BORDERCOLORDARK='#E7EBFF' BORDERCOLORLIGHT='#000000'>"
'If you add so pin verify ,you maybe add these codes as these
'Document.Writeln "<TR><TD ALIGN='right'>Identity:</TD><TD>"
'Document.Writeln "<select name='Identity'>"
'Document.Writeln "<option value='0'>User PIN</option>"
'Document.Writeln "<option value='1'>So PIN</option>"
'Document.Writeln "</select>"
'Document.Writeln "</TD></TR>"

Document.Writeln "<TR><TD ALIGN='right'>Token Pid:</TD><TD><INPUT NAME='TokenPid' CLASS='inputtext'></TD></TR>"
Document.Writeln "<TR><TD ALIGN='right'>User PIN:</TD><TD><INPUT TYPE='password' NAME='UserPIN' CLASS='inputtext'></TD></TR>"


Document.Writeln "</TABLE><P> </P><P ALIGN='center'>"
Document.Writeln "<INPUT TYPE='submit' NAME='Submit' VALUE='Let me in' CLASS='inputbtn'>"
Document.Writeln "<INPUT TYPE='reset' NAME='Reset' VALUE='Re-input' CLASS='inputbtn'></P></FORM>"
-->
</SCRIPT>

</TD>
</TR>
</TABLE>
<H2> </H2>
<P> </P>
<P ALIGN="center">Create by Rockey, 2006-5-18</P>
<P ALIGN="center">Copyright© 2006,Rockey Tech. Co. Ltd.</P>
</BODY>
</HTML>



...全文
759 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
qqpass2009 2009-02-22
  • 打赏
  • 举报
回复
2、verify.aspx


<%@ Page Language="C#" Description="ET99 Demo ---ASP.NET" %>
<%@ Import Namespace="System"%>
<%@ Import Namespace="System.IO"%>
<%@ Import Namespace="System.Security"%>
<%@ Import Namespace="System.Security.Cryptography"%>
<%@ Import Namespace="System.Text"%>

<script language="c#" runat=server>
//by Yangsheng Zhu
//Date: 2003/6/3
//MD5 Function

string fun_MD5(string str)
{
byte[] b = System.Text.Encoding.GetEncoding(1252).GetBytes(str);
b=new System.Security.Cryptography.MD5CryptoServiceProvider().ComputeHash(b);
string ret="";
for(int i=0;i<b.Length;i++)
ret+=b[i].ToString("x").PadLeft(2,'0');
return ret;
}

Byte[] hexstr2array(string HexStr)
{
string HEX = "0123456789ABCDEF";
string str = HexStr.ToUpper();
int len = str.Length;
byte[] RetByte = new byte[len/2];
for(int i=0; i<len/2; i++)
{
int NumHigh = HEX.IndexOf(str[i*2]);
int NumLow = HEX.IndexOf(str[i*2+1]);

RetByte[i] = Convert.ToByte(NumHigh*16+NumLow);
}
return RetByte;
}
</script>

<%

string clientrandom = Session["Message"].ToString();
string username = Request.Form["SN_SERAL"];
string clientdigest = Request.Form["Digest"];
string filename = this.MapPath("user.txt");

//Read from file and Get the user pwd
string userpwd="";
StreamReader srReadLine = new StreamReader((System.IO.Stream)File.OpenRead(filename),
System.Text.Encoding.ASCII);

srReadLine.BaseStream.Seek(0, SeekOrigin.Begin);
bool b_break = true;
while (srReadLine.Peek() > -1 && b_break)
{
if (Object.Equals(srReadLine.ReadLine(),username))
{
userpwd = srReadLine.ReadLine();
b_break = false;
}
}
srReadLine.Close();

//these for MD5_HMAC
string ipad="";
string opad="";

{
for(int i=0; i<64; i++)
{
ipad += "6";
opad += "\\";
}
}

string Password= userpwd;

int KLen = Password.Length;
string iResult = "";
{
for(int i = 0; i < 64; i++)
{
if(i < KLen)
iResult += Convert.ToChar(ipad[i] ^ Password[i]);
else
iResult += Convert.ToChar(ipad[i]);
}
}
iResult += clientrandom;
iResult = fun_MD5(iResult);

byte[] Test = hexstr2array(iResult);

iResult = "";

char[] b = System.Text.Encoding.GetEncoding(1252).GetChars(Test);

for(int i=0;i<b.Length;i++)
{
iResult += b[i];
}

string oResult = "";
{
for (int i=0; i<64; i++)
{
if (i < KLen)
oResult += Convert.ToChar(opad[i] ^ Password[i]);
else
oResult += Convert.ToChar(opad[i]);
}
}

oResult += iResult;

string Result = fun_MD5(oResult).ToUpper();
if ( Object.Equals(Result,clientdigest))
Message.Text += "<br> Congratulations! ::: "+username;
else
Message.Text += "<br>Sorry ,maybe your password is not correct! " ;

Message.Text += "<br>Client Digest:" + clientdigest;
Message.Text += "<br>Server Digest:" + Result;
Message.Text += "<br>Random:" + clientrandom;

%>
<html>

<body>
<asp:label id="Message" forecolor="red" font-bold="true" runat=server/><br>
</body>
</html>


请大虾帮帮助,把这两个ASPX面页写成一个前台ASPX面页,一个后到ASPX.CS面页!

62,067

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

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