2

I am attempting to encrypt an image, post to IPFS, get the image back from IPFS and decrypt. I have successfully achieved this with string data with no issues. When I try to do the same with image data, I can encrypt, store and retrieve from IPFS fine, but when I try to decrypt I get this error with no other information at all 'This message cannot be decrypted'. This is clearly not very helpful at all and I have no clues as to why this wouldn't work.

Encrypting/decrypting text which works perfectly fine

const encryptedData = ethUtil.bufferToHex(
Buffer.from(JSON.stringify(sigUtil.encrypt({
          publicKey: this.state.publicKey,
          data: JSON.stringify(this.state.credential),
          version: 'x25519-xsalsa20-poly1305',
        })), 'utf8')
);
let decryptedMessage = await window.ethereum.request({
    method: 'eth_decrypt',
    params: [encryptedMessage, this.props.account],
}).catch((error) => window.alert(error.message));
decryptedMessage = JSON.parse(decryptedMessage);

Trying the same thing with an image that is submitted via a form:

let reader = new window.FileReader();
let that = this;
reader.onloadend = function () {
let res = reader.result;
that.setState({photoString: res});
}
await reader.readAsText(photoFile);

// Encrypt photo using MetaMask const encryptedPhoto = ethUtil.bufferToHex( Buffer.from(JSON.stringify(sigUtil.encrypt({ publicKey: this.state.publicKey, data: this.state.photoString, version: 'x25519-xsalsa20-poly1305', })), 'utf8') );

Amber
  • 21
  • 1
  • Perhaps it is related to his question https://ethereum.stackexchange.com/questions/120597/size-limit-decrypting-files-with-metamask. – Ismael Feb 26 '22 at 18:22
  • I got the same error while accidentally using the wrong MetaMask account to decrypt the data. – rvanlaarhoven May 25 '22 at 07:14

0 Answers0