設為首頁收藏本站Access中國

Office中國論壇/Access中國論壇

 找回密碼
 注冊

QQ登錄

只需一步,快速開始

12下一頁
返回列表 發(fā)新帖
查看: 9353|回復: 15
打印 上一主題 下一主題

[模塊/函數(shù)] 【轉(zhuǎn)載 / 源碼】MD5加密的VB類模塊源碼

[復制鏈接]
跳轉(zhuǎn)到指定樓層
1#
發(fā)表于 2005-9-8 20:01:00 | 只看該作者 回帖獎勵 |倒序瀏覽 |閱讀模式
標 題:改了個MD5的VB類模塊源碼,可支持中文,也沒有網(wǎng)上流傳的那個超過16位就錯了的毛病! (11千字)

發(fā)信人:simonyan

時 間:2002-11-4 14:31:00

詳細信息:

<BLOCKQUOTE>那個網(wǎng)上的MD5.BAS我研究了下,有嚴重問題.只好另找了個自已改了下.

在窗體中調(diào)用時如下:

Dim md5 As New class 'class 為你存的類?烀

Text1.Value=md5.MD5_string_calc(sourcestring)



類模塊源碼如下:









<DIV class=quote>Option Explicit



' Visual Basic MD5 Implementation

' Robert Hubley and David Midkiff (mdj2023@hotmail.com)

' modify by simonyan, Support chinese

' Standard MD5 implementation optimised for the Visual Basic environment.

' Conforms to all standards and can be used in digital signature or password

' protection related schemes.



Private Const OFFSET_4 = 4294967296#

Private Const MAXINT_4 = 2147483647

Private State(4) As Long

Private ByteCounter As Long

Private ByteBuffer(63) As Byte

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

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

Public Function Md5_String_Calc(SourceString As String) As String

    MD5Init

    MD5Update LenB(StrConv(SourceString, vbFromUnicode)), StringToArray(SourceString)

    MD5Final

    Md5_String_Calc = GetValues

End Function

Public Function Md5_File_Calc(InFile As String) As String

On Error GoTo errorhandler

GoSub begin



errorhandler

    DigestFileToHexStr = ""

    Exit Function

   

begin:

    Dim FileO As Integer

    FileO = FreeFile

    Call FileLen(InFile)

    Open InFile For Binary Access Read As #FileO

    MD5Init

    Do While Not EOF(FileO)

        Get #FileO, , ByteBuffer

        If Loc(FileO) < LOF(FileO) Then

            ByteCounter = ByteCounter + 64

            MD5Transform ByteBuffer

        End If

    Loop

    ByteCounter = ByteCounter + (LOF(FileO) Mod 64)

    Close #FileO

    MD5Final

    Md5_File_Calc = GetValues

End Function

Private Function StringToArray(InString As String) As Byte()

    Dim I As Integer, bytBuffer() As Byte

    ReDim bytBuffer(LenB(StrConv(InString, vbFromUnicode)))

    bytBuffer = StrConv(InString, vbFromUnicode)

    StringToArray = bytBuffer

End Function

Public Function GetValues() As String

    GetValues = LongToString(State(1)) & LongToString(State(2)) & LongToString(State(3)) & LongToString(State(4))

End Function

Private Function LongToString(Num As Long) As String

        Dim A As Byte, B As Byte, C As Byte, D As Byte

        A = Num And &HFF&

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

        B = (Num And &HFF00&) \ 256

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

        C = (Num And &HFF0000) \ 65536

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

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

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

End Function



Public Sub MD5Init()

    ByteCounter = 0

    State(1) = UnsignedToLong(1732584193#)

    State(2) = UnsignedToLong(4023233417#)

    State(3) = UnsignedToLong
分享到:  QQ好友和群QQ好友和群 QQ空間QQ空間 騰訊微博騰訊微博 騰訊朋友騰訊朋友
收藏收藏 分享分享 分享淘帖 訂閱訂閱

點擊這里給我發(fā)消息

2#
發(fā)表于 2005-9-8 22:10:00 | 只看該作者
提示: 作者被禁止或刪除 內(nèi)容自動屏蔽

點擊這里給我發(fā)消息

3#
發(fā)表于 2005-9-10 21:41:00 | 只看該作者


這個為什么不行?

本帖子中包含更多資源

您需要 登錄 才可以下載或查看,沒有帳號?注冊

x
4#
 樓主| 發(fā)表于 2005-9-10 23:04:00 | 只看該作者
以下是引用真主在2005-9-10 13:41:00的發(fā)言:



這個為什么不行?



Private Sub Form_Current()

Dim c1 As New softdog 'class 為你存的類?烀

a.value = c1.Md5_String_Calc("c")

點擊這里給我發(fā)消息

5#
發(fā)表于 2005-9-11 03:21:00 | 只看該作者
如果A中為已通過MD5加密過的值,C中為錄入原始值,要比對C通過MD5加密的值是否與A一樣,請問代碼如何寫?
6#
 樓主| 發(fā)表于 2005-9-11 19:55:00 | 只看該作者
以下是引用真主在2005-9-10 19:21:00的發(fā)言:



如果A中為已通過MD5加密過的值,C中為錄入原始值,要比對C通過MD5加密的值是否與A一樣,請問代碼如何寫?

這就是用MD5來存儲密碼的好處了,對于一個密碼,先轉(zhuǎn)換成MD5字符串,然后和數(shù)據(jù)庫中存儲的MD5字符串進行比較,相等則密碼相同。
7#
發(fā)表于 2005-11-27 23:48:00 | 只看該作者
非常感謝!
8#
發(fā)表于 2006-2-3 04:15:00 | 只看該作者
不太懂
9#
發(fā)表于 2006-3-8 06:01:00 | 只看該作者
編譯不了啊出錯

但是可以運行





[此貼子已經(jīng)被作者于2006-3-7 22:13:37編輯過]

10#
發(fā)表于 2006-4-26 00:28:00 | 只看該作者
編譯不了啊出錯
您需要登錄后才可以回帖 登錄 | 注冊

本版積分規(guī)則

QQ|站長郵箱|小黑屋|手機版|Office中國/Access中國 ( 粵ICP備10043721號-1 )  

GMT+8, 2025-7-13 07:56 , Processed in 0.110129 second(s), 35 queries .

Powered by Discuz! X3.3

© 2001-2017 Comsenz Inc.

快速回復 返回頂部 返回列表