Skip to content

Generic Hash Example

Andrew Lambert edited this page Nov 26, 2022 · 6 revisions

Generic hashing

libsodium provides general purpose hashing using keyed or unkeyed BLAKE2b/SHA256/SHA512. These hash algorithms are not suitable for password hashing.

BLAKE2b

This example hashes a file using un-keyed BLAKE2b:

  Dim f As FolderItem = GetOpenFolderItem("")
  Dim bs As BinaryStream = BinaryStream.Open(f)
  Dim h As New libsodium.GenericHashDigest()
  Do Until bs.EOF
    h.Process(bs.Read(4096))
  Loop
  MsgBox(libsodium.EncodeHex(h.Value))

SHA512

This example hashes a file using SHA512:

  Dim f As FolderItem = GetOpenFolderItem("")
  Dim bs As BinaryStream = BinaryStream.Open(f)
  Dim h As New libsodium.GenericHashDigest(libsodium.HashType.SHA512)
  Do Until bs.EOF
    h.Process(bs.Read(4096))
  Loop
  MsgBox(libsodium.EncodeHex(h.Value))

SHA256

This example hashes a file using SHA256:

  Dim f As FolderItem = GetOpenFolderItem("")
  Dim bs As BinaryStream = BinaryStream.Open(f)
  Dim h As New libsodium.GenericHashDigest(libsodium.HashType.SHA256)
  Do Until bs.EOF
    h.Process(bs.Read(4096))
  Loop
  MsgBox(libsodium.EncodeHex(h.Value))
Clone this wiki locally