home *** CD-ROM | disk | FTP | other *** search
/ Chip 2002 September / Chip_2002-09_cd1.bin / zkuste / vbasic / Data / Utils / XZipComp.exe / XceedEncryption.Cab / F112954_Utility.bas < prev    next >
Encoding:
BASIC Source File  |  2001-06-27  |  1.0 KB  |  45 lines

  1. Attribute VB_Name = "Utility"
  2. Option Explicit
  3.  
  4. Public Enum enuHashingMethod
  5.     ehmSHA = 0
  6.     ehmHaval = 1
  7. End Enum
  8.  
  9. ' Convert the variant specified to an hexadecimal representation, only if
  10. ' the variant is an array.
  11. Public Function BinaryToHex(ByRef vaBinaryValue As Variant) As String
  12.  
  13.     Dim I As Long
  14.     Dim sNewValue As String
  15.     
  16.     sNewValue = ""
  17.     
  18.     If (VarType(vaBinaryValue) And vbArray) = vbArray Then
  19.         For I = 0 To LenB(vaBinaryValue) - 1
  20.             sNewValue = sNewValue & Right("0" & Hex(CLng(vaBinaryValue(I))), 2)
  21.         Next I
  22.     End If
  23.     
  24.     BinaryToHex = sNewValue
  25.  
  26. End Function
  27.  
  28. ' Convert the hexadecimal string to a byte array return as a variant
  29. Public Function HexToBinary(ByRef sHexValue As String) As Variant
  30.  
  31.     Dim I As Long
  32.     Dim NewValue() As Byte
  33.     
  34.     I = 0
  35.     While I < Len(sHexValue)
  36.         ReDim Preserve NewValue(I / 2)
  37.         NewValue(I / 2) = Val("&H" & Mid$(sHexValue, I + 1, 2))
  38.         I = I + 2
  39.     Wend
  40.     
  41.     HexToBinary = NewValue
  42.  
  43. End Function
  44.  
  45.