| 网站首页 | 数学工具相关 | office软件使用 | 数学试卷 | 数学课件 | 数学教案 | 资源下载 | 请您留言 | 
  {$MY_AD_Banner}
您现在的位置: 数学工具网 >> office软件使用 >> 电脑技术 >> 正文 用户登录 新用户注册
VB 获取文件MD5 ——调用 Cryptdll.dll 完成         ★★★
VB 获取文件MD5——调用 Cryptdll.dll 完成
VB 获取文件MD5——调用 Cryptdll.dll 完成
作者:佚名 文章来源:网络 点击数: 更新时间:2012-5-24 15:46:45

Option Explicit
Option Base 0

Public Type MD5_CTX
    i(1) As Long
    buf(3) As Long
    inc(63) As Byte
    digest(15) As Byte
End Type

Public Declare Sub MD5Init Lib "Cryptdll.dll" (ByVal pContex As Long)
Public Declare Sub MD5Final Lib "Cryptdll.dll" (ByVal pContex As Long)
Public Declare Sub MD5Update Lib "Cryptdll.dll" (ByVal pContex As Long, ByVal lPtr As Long, ByVal nSize As Long)

Public Function ConvBytesToBinaryString(bytesIn() As Byte) As String
    Dim i As Long
    Dim nSize As Long
    Dim strRet As String
   
    nSize = UBound(bytesIn)
    For i = 0 To nSize
         strRet = strRet & Right$("0" & Hex(bytesIn(i)), 2)
    Next
    ConvBytesToBinaryString = strRet
End Function

Public Function GetMD5Hash(bytesIn() As Byte) As Byte()
    Dim ctx As MD5_CTX
    Dim nSize As Long
   
    nSize = UBound(bytesIn) + 1
   
    MD5Init VarPtr(ctx)
    MD5Update ByVal VarPtr(ctx), ByVal VarPtr(bytesIn(0)), nSize
    MD5Final VarPtr(ctx)
   
    GetMD5Hash = ctx.digest
End Function

Public Function GetMD5Hash_Bytes(bytesIn() As Byte) As String
    GetMD5Hash_Bytes = ConvBytesToBinaryString(GetMD5Hash(bytesIn))
End Function

Public Function GetMD5Hash_String(ByVal strIn As String) As String
    GetMD5Hash_String = GetMD5Hash_Bytes(StrConv(strIn, vbFromUnicode))
End Function

Public Function GetMD5Hash_File(ByVal strFile As String) As String
    Dim lFile As Long
    Dim bytes() As Byte
    Dim lSize As Long
   
    lSize = FileLen(strFile)
    If (lSize) Then
        lFile = FreeFile
        ReDim bytes(lSize - 1)
        Open strFile For Binary As lFile
        Get lFile, , bytes
        Close lFile
        GetMD5Hash_File = GetMD5Hash_Bytes(bytes)
    End If
End Function

{$MY_AD_Squar_article_left}
文章录入:admin    责任编辑:admin 
  • 上一篇文章:

  • 下一篇文章:
  • 【字体: 】【发表评论】【加入收藏】【告诉好友】【打印此文】【关闭窗口
    专 题 栏 目
    最 新 热 门
    最 新 推 荐
    相 关 文 章
    VB 获取文件MD5 ——调用…
    Word文档的另类加密方法…
    网友评论:(只显示最新10条。评论内容只代表网友观点,与本站立场无关!)
     

    数学工具版权所有 Copyright © 2015-2020 mathtool.cn. All Rights Reserved .
    浙ICP备15030860号 联系方式 QQ:87735874 E_mail:zhangyongsc@163.com