|
3#
楼主 |
发表于 2011-9-5 21:34:10
|
只看该作者
本帖最后由 willland 于 2011-9-5 21:51 编辑
分享是王道。。。搞了几个小时,终于搜出了一个可用的方法。。。不容易啊,申请加精。。。
'--------------------------------------------------------------------------------------------------------------------------
'Summary: 调用capicom.dll计算哈希值(下载并注册组件capicom.dll)
'Author: 刘汝锋
'Date: 2011.08.30
Const CAPICOM_HASH_ALGORITHM_MD2 = 1
Const CAPICOM_HASH_ALGORITHM_MD4 = 2
Const CAPICOM_HASH_ALGORITHM_MD5 = 3
Const CAPICOM_HASH_ALGORITHM_SHA1 = 0
Const CAPICOM_HASH_ALGORITHM_SHA_256 = 4
Const CAPICOM_HASH_ALGORITHM_SHA_384 = 5
Const CAPICOM_HASH_ALGORITHM_SHA_512 = 6
'将字符转化为二进制格式
Function Str2Strb(str)
For i = 1 to Len(str)
tmp = Mid(str,i,1)
reStr = reStr & chrB(ascB(tmp))
Next
Str2Strb = reStr
End Function
'函数Hash()
Function Hash(str)
Dim HashedData
Set HashedData = CreateObject("CAPICOM.HashedData")
HashedData.Algorithm = CAPICOM_HASH_ALGORITHM_SHA_1
'将"SHA_1"换成"MD5"就可以计算MD5码了
HashedData.Hash Str2Strb(str)
Hash = LCase(HashedData.Value)
'LCase()表示返回小写字符
End Function |
|