【发布时间】:2019-12-30 13:06:31
【问题描述】:
我正在维护一个客户 Classic ASP 网站,在特定位置发现了一些 ASP.NET 代码。我需要有人帮助我理解每一行的含义,因为我必须用经典的 ASP 函数替换这段 ASP.NET 代码。
据我了解,代码执行如下:
- 获取Request.QueryString“digest”,并将其放入名为“str”的变量中
- 将 Response.ContentType 设置为“text/plain”
- 使用“str”变量调用“HashCode”函数。此“HashCode”函数执行以下操作:
- 创建一个名为“hash”的 SHA1 哈希引擎实例
- 创建一个名为“encoder”的 UTF8 字符串编码器实例
- 计算变量“combined”,它必须是从“str”参数派生的字节序列
- 获取“组合”的 SHA1 哈希
- 返回先前计算的“组合”SHA1 哈希的 Base64 编码值
- Response.Write 这个返回值。
我想确保我没有遗漏任何其他内容。我的理解是否全面完整?
<%@ WebHandler Language="C#" Class="digets" %>
using System;
using System.Web;
public class digets : IHttpHandler {
public void ProcessRequest (HttpContext context) {
string str= context.Request.QueryString.Get("digest");
context.Response.ContentType = "text/plain";
context.Response.Write(HashCode(str));
}
public static string HashCode(string str)
{
string rethash = "";
try
{
System.Security.Cryptography.SHA1 hash = System.Security.Cryptography.SHA1.Create();
System.Text.UTF8Encoding encoder = new System.Text.UTF8Encoding();
byte[] combined = encoder.GetBytes(str);
hash.ComputeHash(combined);
rethash = Convert.ToBase64String(hash.Hash);
}
catch (Exception ex)
{
string strerr = "Error in HashCode : " + ex.Message;
}
return rethash;
}
public bool IsReusable {
get {
return false;
}
}
}
【问题讨论】: