I retrieve the public key of a users account using Web3 as follows:
web3.eth.sign(web3.eth.accounts[0], web3.sha3('test'), function (err, signature) {
var sigtest = signature
const util = require('ethereumjs-util');
const sig = util.fromRpcSig(sigtest);
const publicKey = util.ecrecover(util.sha3('test'), sig.v, sig.r, sig.s);
});
I then want to encrypt a message with this public key (without having a users private key) - How to encrypt a message with the public-key of an Ethereum address gives an answer but in that example a private key is also given. How should this be done?