Skip to content

Secure Memory Example

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

Secure memory

libsodium offers guarded heap allocations and facilities to limit access to pages of memory. These features are exposed in the SecureMemoryBlock class.

Allocate secure memory

  Dim mb As New libsodium.SecureMemoryBlock(64) ' allocate 64 bytes

Modify secure memory

  Dim mb As New libsodium.SecureMemoryBlock(64) ' allocate 64 bytes
  mb.CString(0) = "Hello, world!"

Read secure memory

  Dim mb As New libsodium.SecureMemoryBlock(64) ' allocate 64 bytes
  mb.CString(0) = "Hello, world!"
  MsgBox(mb.CString(0)) ' read data

Change the protection of secure memory

  Dim mb As New libsodium.SecureMemoryBlock(64) ' allocate 64 bytes
  mb.ProtectionLevel = libsodium.ProtectionLevel.ReadOnly
Clone this wiki locally