Is there a way to do anonymous encryption to a recipient's Public key, where the only way to open a message would be to decrypt with your own private key + passphrase?
You can write one very easily, but luckily there are libraries for these like Sealed boxes
From the site;
Sealed boxes are designed to anonymously send messages to a recipient given its public key.
Only the recipient can decrypt these messages, using its private key. While the recipient can verify the integrity of the message, it cannot verify the identity of the sender.
A message is encrypted using an ephemeral key pair, whose secret part is destroyed right after the encryption process.
Without knowing the secret key used for a given message, the sender cannot decrypt its own message later. And without additional data, a message cannot be correlated with the identity of its sender. Note: the emphasis is mine.
The sealed boxes based on Crypto boxes that uses
- Key exchange: X25519
- Encryption: XSalsa20 stream cipher
- Authentication: Poly1305 MAC
Keep in mind that the additional data can be, your IP address, your MAC address, your writing style, etc. This may leak your identity or location. You may need some protections/countermeasures like TOR network against the identification of the sender.