Encrypt data for specific peer

I’m trying to learn IPFS, my current goal is to build as simple system as I can which allows for one peer to pass a photo to another peer. I assume that the both peers are connected to the network, I also ignore the question of how to find the other peer (I’ll post a question about that separately). I also not looking for long-term storage in the network, after the receiving node has the image it stores it locally.

I saw some questions and discussions about encrypting data before adding it to IPFS, I also saw the wip spec for ipfs crypt but I don’t see any guidelines nor example code for encrypting data, please refer me if there is something like that.

My questions:

  1. Is it good idea/practice to use the node identity key for encryption? For example, I can use the node PubKey to encrypt the data, that way I can be sure that only that specific node will be able to decrypt it.
  2. Is there a good way to obtain the PubKey of a specific node?
1 Like

for crypt your data you can use https://nodejs.org/api/crypto.html (for example) after crypt event you can add your buffer into ipfs.

Thanks.
What about using the public key of the other peer - is that recommended or should I generate a key-pair specifically for this communication?

create your key-pair i think can increase security on your sharing.