Skip to content

PKI Digital Signature Examples

Andrew Lambert edited this page Jan 21, 2023 · 10 revisions

Public key signatures

libsodium offers facilities to sign and verify data using the private key of one user and the public key of the other; nothing secret needs to be exchanged.

Generate a new random key pair

  Dim key As libsodium.PKI.SigningKey
  key = key.Generate()

Generate a new key pair key from a seed

Use the same seed to generate the same key

  Dim key As libsodium.PKI.SigningKey
  key = key.Generate(key.RandomSeed)

Generate a new signing key from a password (PBKDF2)

Use the same password, salt, and resource limits to generate the same key

  Dim passwd As New libsodium.Password("seekritpassword")
  Dim key As New libsodium.PKI.SigningKey(passwd, passwd.RandomSalt, libsodium.ResourceLimits.Interactive)

Sign data

  Dim mykey As libsodium.PKI.SigningKey
  mykey = mykey.Generate() ' random key for example
  
  Dim SignedData As MemoryBlock = libsodium.PKI.SignData("Hello, world!", mykey)

Verify data

  Dim theirkey As New libsodium.PKI.PublicKey(libsodium.PKI.SigningKey.Generate) ' random for example
  Dim SignedData As MemoryBlock ' the signed message, assume valid for example
  Dim Data As MemoryBlock = libsodium.PKI.VerifyData(SignedData, theirkey)
Clone this wiki locally