-
-
Notifications
You must be signed in to change notification settings - Fork 3
libsodium.PKI.SharedSecret.DeriveSharedSecret
libsodium.PKI.SharedSecret.DeriveSharedSecret
Shared Function DeriveSharedSecret(RecipientPublicKey As MemoryBlock, SenderPrivateKey As libsodium.PKI.EncryptionKey) As MemoryBlock
Name | Type | Comment |
---|---|---|
RecipientPublicKey | MemoryBlock | The public half of the recipient's key pair.. |
SenderPrivateKey | EncryptionKey | The sender's key pair. |
The shared secret data.
WARNING: This is (probably) not the method you are looking for. You probably want SharedSecret.Constructor(RecipientPublicKey, SenderPrivateKey).
Computes a shared secret (NOT a key) given a SenderPrivateKey
and RecipientPublicKey
.
The return value represents the X coordinate of a point on the curve. As a result, the number of possible keys is limited to the group size (≈2252; smaller than the key space), and the key distribution is not uniform. In addition, different values of RecipientPublicKey
and SenderPrivateKey
may return the same X coordinate.
For this reason, instead of directly using the return value as a shared key, it is recommended to generate a hash of the return value concatenated with both users' public keys:
Dim secret As MemoryBlock = libsodium.PKI.SharedSecret.DeriveSharedSecret(RecipientPublicKey, SenderPrivateKey)
Dim key As String = libsodium.GenericHash(secret + RecipientPublicKey + SenderPublicKey)
Or just use the Constructor method which does this automatically:
Dim key As New libsodium.PKI.SharedSecret(RecipientPublicKey, SenderPrivateKey)
Wiki home | Project page | Bugs | Become a sponsor
Text and code examples are Copyright ©2016-24 Andrew Lambert, offered under the CC BY-SA 3.0 License.
- libsodium module
- FAQ
-
Examples
- Secure memory
- Password hashing
- Generic hashing
- Encrypting streams or files
- PKI
- Encryption
- Digital signatures
- SKI
- Encryption
- Message authentication