How to hash a UTF-8 string in Classic ASP

后端 未结 6 1970
终归单人心
终归单人心 2021-01-15 19:33

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

6条回答
  •  无人及你
    2021-01-15 19:56

    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.

    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.

    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.

提交回复
热议问题