Skip to content

Password Example

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

Password-based functions

Use the Password class to securely hash, verify, and derive cryptographic keys from password data.

Initialize a Password object

  Dim pw As libsodium.Password = "seekrit"

Generate a hash

  Dim pw As libsodium.Password = "seekrit"
  Dim hash As String = pw.GenerateHash()

Verify a hash

  Dim pw As libsodium.Password = "seekrit"
  Dim hash As String = pw.GenerateHash() ' the hash from (e.g.) the database, generated here for the example
  If Not pw.VerifyHash(hash) Then MsgBox("Bad password!")

Generate a new signing key pair from a password

A key for use in message signatures.

  Dim pw As libsodium.Password = "seekrit"
  Dim key As New libsodium.PKI.SigningKey(pw, pw.RandomSalt, libsodium.ResourceLimits.Interactive)

Generate a new encryption key pair from a password

A key for use in asymmetric encryption.

  Dim pw As libsodium.Password = "seekrit"
  Dim key As New libsodium.PKI.EncryptionKey(pw, pw.RandomSalt, libsodium.ResourceLimits.Interactive)

Generate a new secret key from a password

A key for use in symmetric encryption and message authentication.

  Dim pw As libsodium.Password = "seekrit"
  Dim key As New libsodium.SKI.SecretKey(pw, pw.RandomSalt, libsodium.ResourceLimits.Interactive)
Clone this wiki locally