На примере последнего кода из
vbscript: вычисление хэша MD5 строки — Серый форум:
Код:
Option Explicit
Const CAPICOM_HASH_ALGORITHM_MD5 = 3
Dim strText
Dim objHashedData
strText = "Мама мыла раму."
On Error Resume Next
Set objHashedData = WScript.CreateObject("CAPICOM.HashedData")
If Err.Number <> 0 Then
Err.Clear
On Error Goto 0
WScript.Echo "Can't create object [CAPICOM.HashedData]."
WScript.Quit 1
End If
On Error Goto 0
With objHashedData
.Algorithm = CAPICOM_HASH_ALGORITHM_MD5
.Hash UStr2BStr(strText)
WScript.Echo "String: [" & strText & "]"
WScript.Echo "MD5 Hash: [" & .Value & "]"
End With
Set objHashedData = Nothing
WScript.Quit 0
'=============================================================================
'=============================================================================
' Based on «md5test.vbs.txt» (http://www.daleanderson.ca/code/wsh/md5test%2Evbs.txt)
'
' Unicode string to Byte string conversion
'=============================================================================
Function UStr2BStr(strText)
Dim i
Dim strResult
strResult = ""
For i = 1 To Len(strText)
strResult = strResult & ChrB(Asc(Mid(strText, i, 1)))
Next
UStr2BStr = strResult
End Function
'=============================================================================
Можете сравнить с исходным, чтобы увидеть отличия.