MD5 on ASP Classic and .NET
I have a working .NET web application that perform hashing and encryption using MD5 on a certain string. This string will be stored in a cookie.
Th开发者_如何学Pythone problem is, I will need to validate this cookie from an ASP classic application.
From what I know, there are no built in cryptographic providers in ASP classic, thus I may need to copy/write my own implementation of the MD5 algorithm.
Is there any implementation ready to use, preferably open source (I don't want rogue code sending strings around the world), and compatible with the .NET counterpart?
Create your own .net DLL only with the bytes needed to perform the validation and then call it from ASP!
Here is how: Exposing .NET Components to COM
Much of the .Net Cryptography namespace is just a wrapper around Windows' CryptoAPI, you may be able to work directly with that, but that could end up being a pain. This page may be helpful... http://www.codeproject.com/KB/asp/adrian_bacaianu.aspx
A quick web search for VBScript MD5 turned up lots
Rather than cut and paste the nicest one I found was here
You can use Javascript in classic ASP, even if your preferred language is VBScript (or something else).
The Google Closure library, which is implemented in Javascript, includes an MD5 hash class. As the Closure lib is licensed via the Apache Source License, anyone is free to modify and re-use it.
Here is a version of that MD5 hash that has been modified to be usable without any of the Closure pre-requisites. You can use it like this:
var md5 = new Md5();
md5.update(bytes); // array of byte values
hash = md5.digest();
If you'd like to compute the MD5 hash of a string, there is a string extension like this:
// extension to the string object
if (typeof String.prototype.toMd5 != 'function') {
String.prototype.toMd5 = function () {
var s = this, bytes = [], i, L = s.length, c,
md5, hash;
// assume all 8-bit chars (eg, ascii, IBM-437, etc);
// take lower 8 bits of each string char.
for (i = 0; i < L; ++i) {
c = s.charCodeAt(i);
bytes.push(c & 255);
}
md5 = new Md5();
md5.update(bytes);
hash = md5.digest();
return hash;
};
}
Include the md5 class into your .asp file like this:
<%@ language="Javascript" %>
<script language="Javascript" runat="server" src='md5.js'></script>
<script language="Javascript" runat="server" src='arrayExtensions.js'></script>
<script language="Javascript" runat="server">
(function() {
...
}());
</script>
And you can use it from within Javascript like this:
var subject="The quick brown fox jumps over the lazy dog",
hash = subject.toMd5(),
g = hash.map(function(x){return x.toString(16);}),
stringRep = g.join('');
Printing out stringRep
gives 9e107d9d372bb6826bd81d3542a419d6
as expected.
Using that Md5 class from within VBScript requires a shim.
this seem ok
精彩评论