- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我需要在我的应用程序中生成一个 MD5。
我试过谷歌,但只找到 MD5 的 PHP 代码。我需要连接到使用 MD5 哈希验证的客户端系统,但它们的代码是 PHP 的,我的是使用 VBScript 的 Classic ASP。
我的服务器支持 .Net,所以我不能使用 PHP 脚本。经典 ASP 中的 VBScript 是否有这样的 MD5 代码?
最佳答案
更新 2017-02-21 - 现在为 JWT 添加了 HMACSHA256
更新 2016-07-05 - 现在添加了 SHA1 和 SHA256
是的,对于所有一直在为此苦苦挣扎并想知道的人(如我自己),这是可能的!
下面的代码被分成几个函数,这样你就可以 MD5/sha1/sha256 一个字符串或一个文件。
我从另一个 stackexchange 借用了函数 GetBytes 和 BytesToBase64,stringToUTFBytes 中的代码基于另一个 stackexchange。
function md5hashBytes(aBytes)
Dim MD5
set MD5 = CreateObject("System.Security.Cryptography.MD5CryptoServiceProvider")
MD5.Initialize()
'Note you MUST use computehash_2 to get the correct version of this method, and the bytes MUST be double wrapped in brackets to ensure they get passed in correctly.
md5hashBytes = MD5.ComputeHash_2( (aBytes) )
end function
function sha1hashBytes(aBytes)
Dim sha1
set sha1 = CreateObject("System.Security.Cryptography.SHA1Managed")
sha1.Initialize()
'Note you MUST use computehash_2 to get the correct version of this method, and the bytes MUST be double wrapped in brackets to ensure they get passed in correctly.
sha1hashBytes = sha1.ComputeHash_2( (aBytes) )
end function
function sha256hashBytes(aBytes)
Dim sha256
set sha256 = CreateObject("System.Security.Cryptography.SHA256Managed")
sha256.Initialize()
'Note you MUST use computehash_2 to get the correct version of this method, and the bytes MUST be double wrapped in brackets to ensure they get passed in correctly.
sha256hashBytes = sha256.ComputeHash_2( (aBytes) )
end function
function sha256HMACBytes(aBytes, aKey)
Dim sha256
set sha256 = CreateObject("System.Security.Cryptography.HMACSHA256")
sha256.Initialize()
sha256.key=aKey
'Note you MUST use computehash_2 to get the correct version of this method, and the bytes MUST be double wrapped in brackets to ensure they get passed in correctly.
sha256HMACBytes = sha256.ComputeHash_2( (aBytes) )
end function
function stringToUTFBytes(aString)
Dim UTF8
Set UTF8 = CreateObject("System.Text.UTF8Encoding")
stringToUTFBytes = UTF8.GetBytes_4(aString)
end function
function bytesToHex(aBytes)
dim hexStr, x
for x=1 to lenb(aBytes)
hexStr= hex(ascb(midb( (aBytes),x,1)))
if len(hexStr)=1 then hexStr="0" & hexStr
bytesToHex=bytesToHex & hexStr
next
end function
Function BytesToBase64(varBytes)
With CreateObject("MSXML2.DomDocument").CreateElement("b64")
.dataType = "bin.base64"
.nodeTypedValue = varBytes
BytesToBase64 = .Text
End With
End Function
'Special version that produces the URLEncoded variant of Base64 used in JWTs.
Function BytesToBase64UrlEncode(varBytes)
With CreateObject("MSXML2.DomDocument").CreateElement("b64")
.dataType = "bin.base64"
.nodeTypedValue = varBytes
BytesToBase64UrlEncode = replace(replace(replace(replace(replace(.Text,chr(13),""),chr(10),""),"+", "-"),"/", "_"),"=", "")
End With
End Function
Function GetBytes(sPath)
With CreateObject("Adodb.Stream")
.Type = 1 ' adTypeBinary
.Open
.LoadFromFile sPath
.Position = 0
GetBytes = .Read
.Close
End With
End Function
BytesToBase64(md5hashBytes(stringToUTFBytes("Hello World")))
bytesToHex(md5hashBytes(stringToUTFBytes("Hello World")))
bytesToHex(sha1hashBytes(stringToUTFBytes("Hello World")))
bytesToHex(sha256hashBytes(stringToUTFBytes("Hello World")))
BytesToBase64(md5hashBytes(GetBytes(sPath)))
'define the JWT header, needs to be converted to UTF bytes:
aHead=stringToUTFBytes("{""alg"":""HS256"",""typ"":""JWT""}")
'define the JWT payload, again needs to be converted to UTF Bytes.
aPayload=stringToUTFBytes("{""sub"":""1234567890"",""name"":""John Doe"",""admin"":true}")
'Your shared key.
theKey="mySuperSecret"
aSigSource=stringToUTFBytes(BytesToBase64UrlEncode(aHead) & "." & BytesToBase64UrlEncode(aPayload))
'The full JWT correctly Base 64 URL encoded.
aJWT=BytesToBase64UrlEncode(aHead) & "." & BytesToBase64UrlEncode(aPayload) & "." & BytesToBase64UrlEncode(sha256HMACBytes(aSigSource,stringToUTFBytes(theKey)))
关于asp-classic - 如何在经典 ASP 中使用 VBScript 生成 MD5?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10198690/
我想知道是否有人可以帮助我,因为我对我认为导致简单错误的简单原因视而不见。 我有这个代码: doRound1(x1) denom1 = 5 y1 = denom1 - x1 mod deno
我有以下代码,注释详细说明了会发生什么: averageNum = myArray2(0) 'assign variable response.write(TypeName(averageNum)&"
我有以下脚本,它在本地运行良好(Windows 10 IIS、Windows 2003 Server),但不适用于我们的托管服务器(Windows 2003 Server)。任何超过 4mb 的下载都
ASP Classic 是否具有等同于 PHP 的“包含一次”功能的功能? 最佳答案 我知道这是一个古老的话题,但我想如果有人感兴趣,我会加上我的两分钱。 我编写了一个函数,它完全符合您的要求:无论调
我在Windows 7中运行IIS 7.5,并且已经进入“打开或关闭Windows功能”并在“Internet信息服务/万维网服务/应用程序开发功能”中启用了ASP。一旦做完,我开始收到一个HTTP
我正在尝试从 MS Access 数据库创建一个 ID(主键和自动增量)以用作登录密码。但我收到此错误: Microsoft OLE DB Provider for ODBC Drivers erro
我已经为 Classic ASP(VBScript) + firephp 编写了一个开源调试类,想知道是否可以获取传递给函数的变量的名称?我进行了搜索,但似乎找不到任何技巧来执行此操作。 例子 代码:
我正在尝试从 MS Access 数据库中创建一个 ID(主键和自动增量)以用作登录密码。但是我收到了这个错误: Microsoft OLE DB Provider for ODBC Drivers
我有一个结帐表格,其中产品的数量可以是“n”。那么我如何知道表单中有多少输入字段并从中获取输入呢? 谢谢 最佳答案 如果它是一组单个控件 - 比如说代表项目的可变数量的复选框 - 解决方案非常简单。对
我刚刚审查了一些旧代码并发现了以下内容(在 foo.asp 中): Const ASP_FILENAME = "foo.asp" ' TODO: Update this to the name of
关注 my last question有谁知道如何在经典 ASP 的应用程序范围内使用字典对象?您不能使用 Scripting.Dictionary - 如果您尝试使用,您将看到类似以下内容: App
我的意思是,像 php'h 包括... 就像是 my_file_to_be_included = "include_me.asp" --> 就我目前所见,有几种选择,但每一种都有某种缺点......
我在哪里可以找到“经典”ASP 代码的编辑器? 最佳答案 如果我要进行大量更改,我总是使用 VS2008(支持智能感知、高亮显示和来自 SP1 的调试),Notepad2对于快速(没有智能感知,只有突
例如,我如何运行下面的 me.test? myvar = 'test' me.myvar ASP 查找方法“myvar”但没有找到。在 PHP 中我可以简单地说 $me->$myvar 但 ASP 的
这是要点: 我有一个我想用asp打的电话,我不关心响应。我只想触发调用,我不希望页面等待响应。根据文档,它应该看起来像这样: dim xmlhttp : set xmlhttp = Server.Cr
示例代码: Dim myObject Set myObject = JSON.parse(someJsonResponseFromTheServer) myFunction(myObject.s
据我所知,VBScript/Classic ASP 中唯一的预处理指令是#include。我不知道这是否是正式名称,但我基本上是在寻找可以在通用 VBScript 之前执行代码或其他指令的代码。 VB
据我所知,VBScript/Classic ASP 中唯一的预处理指令是#include。我不知道这是否是正式名称,但我基本上是在寻找可以在通用 VBScript 之前执行代码或其他指令的代码。 VB
我必须维护一个 ASP 3.0 网站... 我想保护sql语句。 我可以使用此代码保护的选择语句: set cmd = Server.createObject("adodb.command") cmd
我正在使用 WebMatrix 中托管的经典 ASP Web 应用程序。有没有办法调试托管在 WebMatrix 中的网站? 最佳答案 WebMatrix 通过调试工具提供很少(没有)。您可以 Res
我是一名优秀的程序员,十分优秀!