28,391
社区成员
发帖
与我相关
我的任务
分享
'--------------------------------------------------------
'函数名称:ASP MD5加密 UTF-8
'函数作者: 深山老熊 cnbjx
'特别说明:
' 1. CAPICOM组件 win2003服务器默认都有安装,以上没有安装
' 2. .net组件 win2008以上默认都有安装
' 本函数优先使用.NET组件,兼容WINDOWS环境
'--------------------------------------------------------
Function md5(ByRef val)
Dim bytes_data,b_net,utf8
On Error Resume Next
Set utf8 = CreateObject("System.Text.UTF8Encoding")
b_net = (Err.Number = 0)
Err.Clear
'已经是 bytes 时
If VarType(val) = 8209 Then
bytes_data = Val
Else
If b_net Then
bytes_data = utf8.GetBytes_4(val)
Else
With CreateObject("Adodb.Stream")
.Type = 2
.Charset = "utf-8"
.open
.WriteText Val
.Position = 0
.Type = 1
.Position = 3
bytes_data = .Read(-1)
.Close
End With
End If
End If
Set utf8 = Nothing
If b_net Then
With CreateObject("MSXML.DOMDocument").createElement("c")
.DataType = "bin.Hex"
.nodeTypedValue = CreateObject("System.Security.Cryptography.MD5CryptoServiceProvider").ComputeHash_2((bytes_data))
md5 = LCase(.text)
End With
Else
With CreateObject("CAPICOM.HashedData")
.Algorithm = 3
.Hash bytes_data
md5 = LCase(.Value)
End With
End If
End Function
'--------------------------------------------------------
'函数名称:ASP MD5文件加密
'函数作者: 深山老熊 cnbjx
'特别说明: 适合小文件, 大文件请使用组件方式。
'组件下载地址: http://download.csdn.net/download/cnbjx/9406206
'--------------------------------------------------------
Function md5_file(ByVal file)
With CreateObject("Adodb.Stream")
.Type = 1
.Open
.LoadFromFile server.mappath(file)
md5_file = md5(.Read)
.Close
End With
End Function