如何在经典ASP中对UTF-8字符串进行哈希处理 [英] How to hash a UTF-8 string in Classic ASP

查看:130
本文介绍了如何在经典ASP中对UTF-8字符串进行哈希处理的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在寻找Classic ASP脚本,该脚本允许我使用MD5算法对字符串进行哈希处理.我需要将此散列字符串与ASP.NET页面中的相同字符串进行匹配,该字符串使用.NET的MD5散列算法进行散列.

I've been looking for a Classic ASP script that allows me to hash a string using the MD5 algorithm. I need to match this hashed string against the same string in an ASP.NET Page, hashed using .NET's MD5 hashing algorithms.

即使我已经找到了一些用于生成散列值的Classic ASP脚本,也没有找到使用非英语字符(例如ñ)生成正确散列的脚本.

Even though I have found several scripts for Classic ASP that generate the hash, I haven't found one that generates the correct hash using non-English characters (like ñ, for example).

您知道某些在这种情况下可以使用的经典ASP脚本吗?

Do you know some Classic ASP script that works in this particular case?

注意:

我尝试了以下脚本:

http://userpages.umbc.edu/~mabzug1/cs/md5/md5.asp

http://forums.aspfree. com/code-bank-54/asp-classic-md5-hash-82164.html

示例:

字符串:

muñeca

正确的MD5哈希:

ea07bec1f37f4b56ebe368355d1c058f

生成的哈希:

298e60cb1179df15d5772726a3975132

推荐答案

对任何字符串进行哈希处理的第一部分是获取字符串字符的字节数组.创建的字节数组取决于用于字符串的编码类型. .Net字符串以UTF-16编码.我不记得vbscript的编码类型是我的头了,但是可能只是ascii或最好是UTF-8.

The first part of hashing any string is getting a byte array of the string's characters. The byte array created depends on the encoding type used for the string. .Net strings are encoded in UTF-16. I don't recall vbscript's encoding type off the type of my head, but it's probably just ascii or at best UTF-8.

因此,要解决您的问题,您需要做的第一件事就是获取vbscript,以便为您提供一个字节数组,该字节数组表示字符串中的UTF-16字符.然后去寻找直接需要字节数组而不是字符串类型的md5哈希函数.

Therefore, to fix your problem, the first thing you need to do is get vbscript to give you a byte array that represents the UTF-16 characters in your string. Then go look for an md5 hash function that expects a byte array directly, instead of a string type.

不幸的是,即使这可能还不够. vbscript缺少本机UTF-16可能会导致用户输入的字符串中通常次要降低保真度,从而使Classic ASP代码中的字符串为 no与您的ASP.Net代码中的字符串完全相同的字符.如果是这种情况,唯一的解决方案是更改您的ASP.Net代码以匹配经典ASP编码,而不是相反.无论如何,这可能是更容易的解决方案.为此,您将需要准确地知道您的vbscript代码使用的是什么字符.同样,我再也没有这些信息了,所以您可以像我一样搜索它.

Unfortunately, even this may not be enough. It's possible that vbscript's lack of native UTF-16 could result in what is normally a minor loss of fidelity in the string input from the user, such that the string in your Classic ASP code is no longer exactly the same characters as the string in your ASP.Net code. If this is the case, the only solution is to change your ASP.Net code to match the Classic ASP encoding, rather than vice versa. This may be the much easier solution anyway. For this to work, you will need to know exactly what character encoding your vbscript code is using. Again, I don't have that information in my head anymore, so you can google it as well as I.

这篇关于如何在经典ASP中对UTF-8字符串进行哈希处理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆