sindresorhus / Actions

⚙️ Supercharge your shortcuts
https://sindresorhus.com/actions
2.68k stars 115 forks source link

Action proposal: Encrypt/decrypt #220

Closed hepcat72 closed 8 months ago

hepcat72 commented 10 months ago

Description

Since Life360 stopped supporting home automation triggers, and alternative apps have proven to either be buggy and unreliable or battery killers, so I am rolling my own. But I don't want to be sending my geo-coordinates to my raspberry pi in clear text. I would like my webhook shortcut to encrypt my location details for sending and I need to be able to decrypt it with the same algorithm on my raspberry pi. But I'm finding out that a shortcut action to encrypt/decrypt a string (e.g. JSON string) appears to not exist.

I did find a shortcut someone posted on Reddit that claims to do it, but the copy I imported appears to be broken. Even though I think I fixed it, I can't seem to re-implement it on my pi (yet).

This would all be much easier if some app provided an encrypt/decrypt action.

Bonus: generate a random "secret key".

sindresorhus commented 10 months ago

What kind of encryption are you looking for? I would recommend AES-GCM, with the encrypted data encoded as Base64.

hepcat72 commented 10 months ago

As long as it's supported by crypto-js, it'd be great. I installed a node on my node-red instance called crypto-wz which just interfaces with crypto-js. It supports maybe half a dozen protocols. Crypto-wz is a little buggy. Their base64 encoding hits an error which is an issue that was fixed in crypto-js. The one I tested with was AES. Let me bring it up and see if it has AES-GCM.

hepcat72 commented 10 months ago

Looks like the crypto-wz node supports AES, DES, RC4, Rabbit, and TripleDES.

But I could try searching for a node that supports AES-GCM if that's easier for you (beggars can't be choosers, lol).

sindresorhus commented 10 months ago

You could simply use Web Crypto in Node.js: https://stackoverflow.com/questions/66506154/aes-256-gcm-decryption-in-nodejs

sindresorhus commented 10 months ago

Bonus: generate a random "secret key".

You can already do this with the "Generate Random Text" action.

hepcat72 commented 10 months ago

You could simply use Web Crypto in Node.js: https://stackoverflow.com/questions/66506154/aes-256-gcm-decryption-in-nodejs

Going by the name, it sounds like it uses a web service... I was hoping to keep the encryption local. But like I said, beggar ≠ chooser.

sindresorhus commented 10 months ago

No: https://nodejs.org/api/webcrypto.html#web-crypto-api

hepcat72 commented 10 months ago

No: https://nodejs.org/api/webcrypto.html#web-crypto-api

Ah, nice. And it looks like aes gcm is available in a node-red node called crypto-blue.

sindresorhus commented 9 months ago

I added this in the latest TestFlight build: https://testflight.apple.com/join/fJGUrsZx