C# 我对该代码的理解是否正确/完整?

C# 我对该代码的理解是否正确/完整?,c#,asp.net,.net,iis,C#,Asp.net,.net,Iis,我正在维护一个客户经典的ASP网站,在特定的地方发现了一些ASP.NET代码。我需要有人帮助我理解每一行的含义,因为我将不得不用经典的ASP函数替换此ASP.NET代码 根据我的理解,以下是代码执行的功能: 获取Request.QueryString“摘要”,并将其放入名为“str”的变量中 将Response.ContentType设置为“text/plain” 使用“str”变量调用“HashCode”函数。此“HashCode”函数执行以下操作: 创建名为“哈希”的SHA1哈希引擎实例 创

我正在维护一个客户经典的ASP网站,在特定的地方发现了一些ASP.NET代码。我需要有人帮助我理解每一行的含义,因为我将不得不用经典的ASP函数替换此ASP.NET代码

根据我的理解,以下是代码执行的功能:

  • 获取Request.QueryString“摘要”,并将其放入名为“str”的变量中
  • 将Response.ContentType设置为“text/plain”
  • 使用“str”变量调用“HashCode”函数。此“HashCode”函数执行以下操作:
  • 创建名为“哈希”的SHA1哈希引擎实例
  • 创建一个名为“编码器”的UTF8字符串编码器实例
  • 计算变量“combined”,它必须是从“str”参数派生的字节序列
  • 获取“combined”的SHA1散列
  • 返回先前计算的SHA1哈希值的Base64编码值“combined”
  • 响应。写入此返回值
  • 我想确定我没有遗漏任何东西。我的理解是否完整

    <%@ 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;
            }
        }
    
    }
    
    
    使用制度;
    使用System.Web;
    公共类digets:IHttpHandler{
    公共void ProcessRequest(HttpContext上下文){
    string str=context.Request.QueryString.Get(“摘要”);
    context.Response.ContentType=“text/plain”;
    Write(HashCode(str));
    }
    公共静态字符串哈希代码(字符串str)
    {
    字符串rethash=“”;
    尝试
    {
    System.Security.Cryptography.SHA1 hash=System.Security.Cryptography.SHA1.Create();
    System.Text.UTF8Encoding encoder=新的System.Text.UTF8Encoding();
    字节[]组合=编码器.GetBytes(str);
    hash.ComputeHash(组合);
    rethash=Convert.ToBase64String(hash.hash);
    }
    捕获(例外情况除外)
    {
    string strerr=“HashCode中的错误:”+ex.消息;
    }
    返回rethash;
    } 
    公共布尔可重用{
    得到{
    返回false;
    }
    }
    }
    
    是的,你的理解是正确的。
    它将使用HashCode方法生成散列,然后将其写入响应。

    是的,您的理解是正确的。 它将使用HashCode方法生成散列,然后将其写入响应