📄 sohunews.asmx
字号:
<%@ WebService Language="C#" Class="SohuNews" %>
using System;
using System.Text;
using System.Security.Cryptography;
using System.Collections.Specialized;
using System.Web.Services;
[WebService(Namespace="http://www.sohu.com")]
public class SohuNews
{
[WebMethod]
public string[] GetNews(string passport)
{
if(VerifyPassport(passport) == false)
return null;
string[] news = new string[5];
news[0] = "Sohu new1";
news[1] = "Sohu new2";
news[2] = "Sohu new3";
news[3] = "Sohu new4";
news[4] = "Sohu new5";
return news;
}
[WebMethod]
public string Register(string user)
{
return MakePassport(user);
}
public string MakePassport(string src)
{
string key = src;
if(key.Length > 8 )
key = key.Substring(0,8);
else if( key.Length < 8)
key = key.PadRight(8);
UnicodeEncoding ue = new UnicodeEncoding();
byte[] hashSource = ue.GetBytes(key + "sohunews");
SHA512 shaM = new SHA512Managed();
byte[] hashResult = shaM.ComputeHash(hashSource);
string passport = key;
foreach(byte b in hashResult)
passport += b.ToString();
return passport;
}
public bool VerifyPassport(string passport)
{
try
{
string key = passport.Substring(0,8);
UnicodeEncoding ue = new UnicodeEncoding();
byte[] hashSource = ue.GetBytes(key + "sohunews");
SHA512 shaM = new SHA512Managed();
byte[] hashResult = shaM.ComputeHash(hashSource);
string new_passport = key;
foreach(byte b in hashResult)
new_passport += b.ToString();
for(int i=0; i<passport.Length; i++)
{
if( passport[i] != new_passport[i])
return false;
}
return true;
}
catch
{
return false;
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -