導航:首頁 > 版本升級 > 取文件md5api

取文件md5api

發布時間:2025-01-14 00:38:01

1. vb 怎麼獲取文件MD5

Option Explicit
Private Declare Function CryptAcquireContext Lib "advapi32.dll" _
Alias "CryptAcquireContextA" ( _
ByRef phProv As Long, _
ByVal pszContainer As String, _
ByVal pszProvider As String, _
ByVal dwProvType As Long, _
ByVal dwFlags As Long) As Long
Private Declare Function CryptReleaseContext Lib "advapi32.dll" ( _
ByVal hProv As Long, _
ByVal dwFlags As Long) As Long
Private Declare Function CryptCreateHash Lib "advapi32.dll" ( _
ByVal hProv As Long, _
ByVal Algid As Long, _
ByVal hKey As Long, _
ByVal dwFlags As Long, _
ByRef phHash As Long) As Long
Private Declare Function CryptDestroyHash Lib "advapi32.dll" ( _
ByVal hHash As Long) As Long
Private Declare Function CryptHashData Lib "advapi32.dll" ( _
ByVal hHash As Long, _
pbData As Any, _
ByVal dwDataLen As Long, _
ByVal dwFlags As Long) As Long

Private Declare Function CryptGetHashParam Lib "advapi32.dll" ( _
ByVal hHash As Long, _
ByVal dwParam As Long, _
pbData As Any, _
pdwDataLen As Long, _
ByVal dwFlags As Long) As Long
Private Const PROV_RSA_FULL = 1
Private Const CRYPT_NEWKEYSET = &H8
Private Const ALG_CLASS_HASH = 32768
Private Const ALG_TYPE_ANY = 0
Private Const ALG_SID_MD2 = 1
Private Const ALG_SID_MD4 = 2
Private Const ALG_SID_MD5 = 3
Private Const ALG_SID_SHA1 = 4
Enum HashAlgorithm
MD2 = ALG_CLASS_HASH Or ALG_TYPE_ANY Or ALG_SID_MD2
MD4 = ALG_CLASS_HASH Or ALG_TYPE_ANY Or ALG_SID_MD4
MD5 = ALG_CLASS_HASH Or ALG_TYPE_ANY Or ALG_SID_MD5
SHA1 = ALG_CLASS_HASH Or ALG_TYPE_ANY Or ALG_SID_SHA1
End Enum
Private Const HP_HASHVAL = 2
Private Const HP_HASHSIZE = 4
Function HashFile( _
ByVal FileName As String, _
Optional ByVal Algorithm As HashAlgorithm = MD5) As String
Dim hCtx As Long
Dim hHash As Long
Dim lFile As Long
Dim lRes As Long
Dim lLen As Long
Dim lIdx As Long
Dim abHash() As Byte
If Len(Dir$(FileName)) = 0 Then Err.Raise 53

lRes = CryptAcquireContext(hCtx, vbNullString, _
vbNullString, PROV_RSA_FULL, 0)

If lRes = 0 And Err.LastDllError = &H80090016 Then

lRes = CryptAcquireContext(hCtx, vbNullString, _
vbNullString, PROV_RSA_FULL, CRYPT_NEWKEYSET)
End If

If lRes <> 0 Then
lRes = CryptCreateHash(hCtx, Algorithm, 0, 0, hHash)
If lRes <> 0 Then
lFile = FreeFile

Open FileName For Binary As lFile

If Err.Number = 0 Then

Const BLOCK_SIZE As Long = 32 * 1024& ' 32K
ReDim abBlock(1 To BLOCK_SIZE) As Byte
Dim lCount As Long
Dim lBlocks As Long
Dim lLastBlock As Long

lBlocks = LOF(lFile) \ BLOCK_SIZE

lLastBlock = LOF(lFile) - lBlocks * BLOCK_SIZE

For lCount = 1 To lBlocks

Get lFile, , abBlock

lRes = CryptHashData(hHash, abBlock(1), BLOCK_SIZE, 0)

If lRes = 0 Then Exit For

Next
If lLastBlock > 0 And lRes <> 0 Then

ReDim abBlock(1 To lLastBlock) As Byte
Get lFile, , abBlock

lRes = CryptHashData(hHash, abBlock(1), lLastBlock, 0)

End If

Close lFile

End If
If lRes <> 0 Then

lRes = CryptGetHashParam(hHash, HP_HASHSIZE, lLen, 4, 0)
If lRes <> 0 Then
ReDim abHash(0 To lLen - 1)
lRes = CryptGetHashParam(hHash, HP_HASHVAL, abHash(0), lLen, 0)
If lRes <> 0 Then
For lIdx = 0 To UBound(abHash)
HashFile = HashFile & _
Right$("0" & Hex$(abHash(lIdx)), 2)
Next
End If
End If
End If
CryptDestroyHash hHash
End If

End If
CryptReleaseContext hCtx, 0
If lRes = 0 Then Err.Raise Err.LastDllError
End Function

調用測試:
Private Sub Form_Load()
MsgBox HashFile("C:\windows\explorer.exe")
End Sub

2. md5_file — 計算指定文件的 MD5 散列值

總結後的知識希望能幫到你:
函數名:md5_file
(PHP 4 >= 4.2.0, PHP 5, PHP 7, PHP 8)
md5_file — 計算指定文件的 MD5 散列值
說明
md5_file ( string $filename , bool $raw_output = false ) : string
使用 » RSA 數據安全公司的 MD5 報文演算法計算 filename 文件的 MD5 散列值並返回。該散列值為 32 字元的十六進制數字。
參數
filename
文件名
raw_output
如果被設置為 true,那麼報文摘要將以原始的 16 位二進制格式返回。
返回值
成功返回字元串,否則返回 false。
更新日誌
版本 說明
5.1.0 函數改用流 API。這意味著能夠配合封裝器使用該函數,比如 md5_file('http://example.com/..')。
範例
示例 #1 md5_file() 使用範例

3. Nodejs怎麼獲取上傳文件的MD5

可以使用第三方的js庫,比如spark-md5.js。上傳文件後,調用對應的api即可以獲取到上傳文件的md5。

4. java有提供獲取一個壓縮文件的MD5驗證碼的API嗎

JAVA 的MD5加耐答密演算法源代碼

import java.security.*;
import java.security.spec.*;

class MD5_Test{

public final static String MD5(String s){
char hexDigits[] = {
'0', '1', '2', '3', '4', '5'慧旦, '6', '7', '8', '9', 'a', 'b', '昌碧慧c', 'd',
'e', 'f'};
try {
byte[] strTemp = s.getBytes();
MessageDigest mdTemp = MessageDigest.getInstance("MD5");
mdTemp.update(strTemp);
byte[] md = mdTemp.digest();
int j = md.length;
char str[] = new char[j * 2];
int k = 0;
for (int i = 0; i < j; i++) {
byte byte0 = md[i];
str[k++] = hexDigits[byte0 >>> 4 & 0xf];
str[k++] = hexDigits[byte0 & 0xf];
}
return new String(str);
}
catch (Exception e){
return null;
}
}
public static void main(String[] args){
//MD5_Test aa = new MD5_Test();

System.out.print(MD5_Test.MD5("XX"));
}

閱讀全文

與取文件md5api相關的資料

熱點內容
簡述文件夾的操作有哪些 瀏覽:766
dnf90版本buff人偶 瀏覽:690
ps中pdf文件黑點怎麼去除 瀏覽:927
n卡的臨時文件在哪裡 瀏覽:590
移動華為4x解鎖工具 瀏覽:493
有時候微信的文件怎麼發不出去 瀏覽:335
美版5s版本能不能升級系統升級 瀏覽:167
cad自動關閉怎麼找迴文件 瀏覽:289
小螞蟻app怎麼賺錢下載 瀏覽:178
項目部有哪些文件 瀏覽:119
nodejswindows升級 瀏覽:471
焊接工藝規程由哪些技術文件組成 瀏覽:993
無線網怎麼改路由器密碼忘了怎麼辦 瀏覽:408
拳皇安卓模擬器文件 瀏覽:537
win10桌面小鍵盤怎麼關 瀏覽:884
word列印頁邊距 瀏覽:627
韓國個人網站模板 瀏覽:997
win10常用位置 瀏覽:746
游戲王gba版本怎麼玩 瀏覽:962
xperiaz5安卓70 瀏覽:728

友情鏈接