I want to upload a file after encrypting it with user's metamask public address and then user should be able to decrypt it with his metamask private key.How can I implement this functionality?
Asked
Active
Viewed 914 times
-1
-
do you want us to write the code for you ? what have you tried ? – Doruk Apr 17 '18 at 11:12
-
https://ethereum.stackexchange.com/questions/3092/how-to-encrypt-a-message-with-the-public-key-of-an-ethereum-address You can start with this :) – dievardump Dec 08 '20 at 15:04
1 Answers
0
Metamask will allow you to sign data with the private key, but signing something is not the same as encrypting it. Mainly because there is no way to decrypt.
And you definitely won't be able to get the private key from Metamask.
The best thing you can do is to use metamask to sign the user's address. Then you can use that as an encryption key.
const address = web3.eth.accounts[0];
const encryptionKey = web3.eth.personal_sign(address, address);

gaiazov
- 1,908
- 14
- 26
-
I am afraid these will not work as, the recomputing the ecnryption key may not work. Everytime you generate the signature the value would be different. This is because of the nonce added in the singing process. – Mohit Sethi Dec 15 '22 at 10:30