Visual basic 6.0 hash function

18,735

Solution 1

For what purpose are you using the hash? This matters because some hash algorithms such as MD5 are suitable for some purposes, but not others.

This link shows a VB6 implementation of MD5.

Solution 2

Example of using CAPICOM to get a hash

Add CAPICOM.DLL as project reference

uses 
  DIM key As String
  DIM sValue As String

  Dim sEncrypedValue as String 

Dim oCAP As CAPICOM.EncryptedData
Set oCAP = New CAPICOM.EncryptedData

With oCAP.
  .Algorithm.KeyLength = CAPICOM_ENCRYPTION_KEY_LENGTH_56_BITS
  .Algorithm.Name = CAPICOM_ENCRYPTION_ALGORITHM_RC4         
  .SetSecret key
  .Content = sValue 
end with

sEncrypedValue = objCAP.Encrypt(CAPICOM_ENCODE_BASE64)


To Decrypt:
oCAP.SetSecret key
oCAP.Content = sEncrypedValue 
sValue = oCAP.Decrypt(CAPICOM_ENCODE_BASE64)
Share:
18,735
Admin
Author by

Admin

Updated on June 22, 2022

Comments

  • Admin
    Admin almost 2 years

    In my application I need to hash a string before I save it to a text file. Does anyone know how to do that?

  • Steve
    Steve over 13 years
    The whole point of the shl (<<) is to avoid using multiplying by 65599 which is relatively slow. The VB port has TWO multiplications. It would be faster to do this: newHash = the character(c) + (previousHashValue * 65599)
  • Ahmad
    Ahmad about 10 years
    The link is no longer valid. Broken. @RoadWarrior
  • HTTP 410
    HTTP 410 about 10 years
    @Ahmad, I've fixed the link.