IPFS and crypto-js

Hi

Do you have a sample showing how to encrypt/decrypt a file to store/retrieve to/from IPFS using JS and crypto-js module (or a similar module) ?

Thanks

Said

It depends exactly what you’re trying to do, but we do that in peergos. We use tweetnacl.js and scrypt.

Thanks for your answer.
My case study is simple. I’m using IPFS to store and to retrieve some documents. The hash is stored in an Ethereum smart contract. At this stage, no issue as everything works perfectly.
But I’m wondering if there is an easy way to encrypt some files before saving them on IPFS (for example, files containing medical data). And of course, to decrypt these files when they are retrieved from IPFS.
So, how to easily mix encrypt and decrypt calls with ipfs.add and ipfs.get or ipfs.cat.

You can encrypt it easily enough with tweetnacl. The question is how and where do you want to store the decryption key? How do you want to control access? Once you’ve decided on a solution for that you can just encrypt the file with a symmetric key, store the cipher text in ipfs, then store the resulting hash and the random nonce used in encryption in your ethereum contract.

1 Like

Hello Said, I’m also using IPFS for the same purpose as you are. But I’m still working on the part of saving my IPFS generated hash on to the ethereum contract and is down with an error of

Uncaught (in promise) Error: invalid address

I think its because of me trying to save the hash as type bytes in the contract. It would be really helpful if you could shed some light on how you achieved it?