Try this:
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 hSessionKey As Long, ByVal dwFlags As Long, ByRef phHash As Long) As Long
Private Declare Function CryptHashData Lib "advapi32.dll" (ByVal hHash As Long, ByVal pbData As String, 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, ByVal pbData As String, ByRef pdwDataLen As Long, ByVal dwFlags As Long) As Long
Private Declare Function CryptDestroyHash Lib "advapi32.dll" (ByVal hHash As Long) As Long
Private Const SERVICE_PROVIDER As String = "Microsoft Enhanced Cryptographic Provider v1.0" & vbNullChar
Private Const KEY_CONTAINER As String = "GCN SSL Container" & vbNullChar
Private Const HP_HASHVAL As Long = 2
Private Const PROV_RSA_FULL As Long = 1
Private Const CRYPT_VERIFYCONTEXT = &HF0000000
Private Const CRYPT_NEWKEYSET As Long = 8
Private Const CALG_SHA1 As Long = 32772
Public Function GetHash(ByVal strData As String, Optional boolHexOut As Boolean = False) As String
Dim strHash As String
Dim hCryptProv As Long
Dim hHash As Long
Dim lngHashLen As Long
Dim bytActiveChar As Byte
Dim strTmp As String
Call CryptAcquireContext(hCryptProv, KEY_CONTAINER, SERVICE_PROVIDER, PROV_RSA_FULL, 0)
Call CryptCreateHash(hCryptProv, CALG_SHA1, 0, 0, hHash)
Call CryptHashData(hHash, strData, Len(strData), 0)
Call CryptGetHashParam(hHash, HP_HASHVAL, vbNull, lngHashLen, 0)
strHash = String(lngHashLen, vbNullChar)
Call CryptGetHashParam(hHash, HP_HASHVAL, strHash, lngHashLen, 0)
If hHash <> 0 Then CryptDestroyHash hHash
If hCryptProv <> 0 Then CryptReleaseContext hCryptProv, 0
Dim i As Integer
If boolHexOut = True Then
For i = 1 To Len(strHash)
strTmp = strTmp & Right("0" & Hex(Asc(Mid(strHash, i, 1))), 2)
Next
GetHash = strTmp
Else
GetHash = strHash
End If
End Function
Two strings walk into a bar. The first string says to the bartender: 'Bartender, I'll have a beer. u.5n$x5t?*&4ru!2[sACC~ErJ'. The second string says: 'Pardon my friend, he isn't NULL terminated'.