Search code examples
phppublic-key-encryptionlibsodium

Libsodium - php asymmetric message encryption/decryption with only one key pair


I would like to encrypt the message with libsodium library with recipient public_key without my private_key/public_key usage. Later recipient shall be able to decrypt it with his private_key.

Will it be possible with crypto_box_keypair() key pair generated for recipient?

Which function shall I use to for encryption and decryption?

I know this would be possible with openssl, but is it possible at all with libsodium?

Thanks.


Solution

  • For this purpose Sealed Box Encryption seems to be the best approach:

    string \Sodium\crypto_box_seal(string $message, string $publickey)
    

    This will encrypt a message with a user's public key, and then he will be able to decrypt it with his private key. This however address only encryption need (which was the case in my question).