广告广告
  加入我的最爱 设为首页 风格修改
首页 首尾
 手机版   订阅   地图  繁体 
您是第 6948 个阅读者
 
发表文章 发表投票 回覆文章
  可列印版   加为IE收藏   收藏主题   上一主题 | 下一主题   
students1
个人文章 个人相簿 个人日记 个人地图
小人物
级别: 小人物 该用户目前不上站
推文 x2 鲜花 x7
分享: 转寄此文章 Facebook Plurk Twitter 版主评分 复制连结到剪贴簿 转换为繁体 转换为简体 载入图片
推文 x0
[Basic][范例] (VB6)md5的档案验证~~转贴by ku3
此程式取自KU3大大~~
网址如下:http://www.blueshop.com.tw/board/show.asp?subcde=BRD20090119205402X1N&fumcde=FUM200501271723350KG
'以下写在类模组名称为MD5
'--------------------------------------------------------------------------------------------
Option Explicit

'=
'= Class Constants
'=
Private Const OFFSET_4 = 4294967296#
Private Const MAXINT_4 = 2147483647

Private Const S11 = 7
Private Const S12 = 12
Private Const S13 = 17
Private Const S14 = 22
Private Const S21 = 5
Private Const S22 = 9
Private Const S23 = 14
Private Const S24 = 20
Private Const S31 = 4
Private Const S32 = 11
Private Const S33 = 16
Private Const S34 = 23
Private Const S41 = 6
Private Const S42 = 10
Private Const S43 = 15
Private Const S44 = 21


'=
'= Class Variables
'=
Private State(4) As Long
Private ByteCounter As Long
Private ByteBuffer(63) As Byte


'=
'= Class Properties
'=
Property Get RegisterA() As String
RegisterA = State(1)
End Property

Property Get RegisterB() As String
RegisterB = State(2)
End Property

Property Get RegisterC() As String
RegisterC = State(3)
End Property

Property Get RegisterD() As String
RegisterD = State(4)
End Property


'=
'= Class Functions
'=

'
' Function to quickly digest a file into a hex string
' ----- ku3 修改 -----
Public Function DigestFileToHexStr(FileName As String) As String
Dim fi As Long
fi = FreeFile
Open FileName For Binary Access Read As #fi
MD5Init
Do While Not EOF(fi)
Get #fi, , ByteBuffer
If Loc(fi) <= LOF(fi) Then
ByteCounter = ByteCounter + 64
MD5Transform ByteBuffer
End If
Loop
ByteCounter = ByteCounter + (LOF(fi) Mod 64)
Close #fi
MD5Final
DigestFileToHexStr = GetValues
End Function


'
' Function to digest a text string and output the result as a string
' of hexadecimal characters.
' ----- ku3 修改 -----
'
Public Function DigestStrToHexStr(SourceString As String) As String
'SourceString = "中英文混合字串测试"
MD5Init
Dim b() As Byte
b = StrConv(SourceString, vbFromUnicode)
MD5Update UBound(b) + 1, StringToArray(SourceString)
MD5Final
DigestStrToHexStr = GetValues
End Function

'
' A utility function which converts a string into an array of
' bytes.
' ----- ku3 修改 -----
'
Private Function StringToArray(InString As String) As Byte()
Dim I As Integer
Dim bytBuffer() As Byte
bytBuffer = StrConv(InString, vbFromUnicode)
StringToArray = bytBuffer
End Function

'
' Concatenate the four state vaules into one string
'
Public Function GetValues() As String
GetValues = LongToString(State(1)) & LongToString(State(2)) & LongToString(State(3)) & LongToString(State(4))
End Function

'
' Convert a Long to a Hex string
'
Private Function LongToString(Num As Long) As String
Dim a As Byte
Dim b As Byte
Dim c As Byte
Dim d As Byte

a = Num And &HFF&
If a < 16 Then
LongToString = "0" & Hex(a)
Else
LongToString = Hex(a)
End If

b = (Num And &HFF00&) \ 256
If b < 16 Then
LongToString = LongToString & "0" & Hex(b)
Else
LongToString = LongToString & Hex(b)
End If

c = (Num And &HFF0000) \ 65536
If c < 16 Then
LongToString = LongToString & "0" & Hex(c)
Else
LongToString = LongToString & Hex(c)
End If

If Num < 0 Then
d = ((Num And &H7F000000) \ 16777216) Or &H80&
Else
d = (Num And &HFF000000) \ 16777216
End If

If d < 16 Then
LongToString = LongToString & "0" & Hex(d)
Else
LongToString = LongToString & Hex(d)
End If

End Function

'
' Initialize the class
' This must be called before a digest calculation is started
'
Public Sub MD5Init()
ByteCounter = 0
State(1) = UnsignedToLong(1732584193#)
State(2) = UnsignedToLong(4023233417#)
State(3) = UnsignedToLong(2562383102#)
State(4) = UnsignedToLong(271733878#)
End Sub

'
' MD5 Final
'
Public Sub MD5Final()
Dim dblBits As Double

Dim padding(72) As Byte
Dim lngBytesBuffered As Long

padding(0) = &H80

dblBits = ByteCounter * 8

' Pad out
lngBytesBuffered = ByteCounter Mod 64
If lngBytesBuffered <= 56 Then
MD5Update 56 - lngBytesBuffered, padding
Else
MD5Update 120 - ByteCounter, padding
End If


padding(0) = UnsignedToLong(dblBits) And &HFF&
padding(1) = Unsign ..

访客只能看到部份内容,免费 加入会员 或由脸书 Google 可以看到全部内容


此文章被评分,最近评分记录
财富:50 (by 三仙) | 理由: 因为您的参与,让程式设计更容易!!



献花 x0 回到顶端 [楼 主] From:台湾和信超媒体宽带网 | Posted:2009-05-30 08:51 |
k7138
个人文章 个人相簿 个人日记 个人地图
路人甲
级别: 路人甲 该用户目前不上站
推文 x0 鲜花 x5
分享: 转寄此文章 Facebook Plurk Twitter 复制连结到剪贴簿 转换为繁体 转换为简体 载入图片

可以防止中毒 谢


献花 x0 回到顶端 [1 楼] From:台湾中华电信股份有限公司 | Posted:2011-03-25 07:01 |

首页  发表文章 发表投票 回覆文章
Powered by PHPWind v1.3.6
Copyright © 2003-04 PHPWind
Processed in 0.058797 second(s),query:16 Gzip disabled
本站由 瀛睿律师事务所 担任常年法律顾问 | 免责声明 | 本网站已依台湾网站内容分级规定处理 | 连络我们 | 访客留言