Skip to content

libsodium.PKI.EncryptData

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

libsodium.PKI.EncryptData

Method Signatures

 Protected Function EncryptData(ClearText As MemoryBlock, RecipientPublicKey As libsodium.PKI.PublicKey, SenderPrivateKey As libsodium.PKI.EncryptionKey, Nonce As MemoryBlock, Exportable As Boolean = False) As MemoryBlock
 Protected Function EncryptData(ClearText As MemoryBlock, SharedKey As libsodium.PKI.SharedSecret, Nonce As MemoryBlock, Exportable As Boolean = False) As MemoryBlock

Parameters

EncryptData(MemoryBlock, libsodium.PKI.PublicKey, libsodium.PKI.EncryptionKey, MemoryBlock, Boolean) As MemoryBlock

Name Type Comment
ClearText MemoryBlock The data to be encrypted.
RecipientPublicKey PublicKey The public half of the recipient's key pair.
SenderPrivateKey EncryptionKey The sender's key pair.
Nonce MemoryBlock The random nonce to be used.
Exportable Boolean Optional. If True then the return value is encoded in a text-based export format; otherwise the raw binary data is returned.

EncryptData(MemoryBlock, libsodium.PKI.SharedSecret, MemoryBlock, Boolean) As MemoryBlock

Name Type Comment
ClearText MemoryBlock The data to be encrypted.
SharedKey SharedSecret The precomputed shared key to be used.
Nonce MemoryBlock The random nonce to be used.
Exportable Boolean Optional. If True then the return value is encoded in a text-based export format; otherwise the raw binary data is returned.

Return value

The encrypted ClearText prepended with a Poly1305 message authentication code, or Nil on error.

Remarks

Encrypts the ClearText using the XSalsa20 stream cipher with a shared key and a Nonce. This key is either computed from the RecipientPublicKey and SenderPrivateKey or precomputed as a SharedSecret object. A Poly1305 message authentication code is prepended to the returned data, which will be validated by the DecryptData method. On error this method returns Nil.

If Exportable=True then the return value is the encrypted message and its nonce encoded in a plain text format. Both the raw binary and plain text format are understood by the DecryptData method.

See also

Clone this wiki locally