Can multiple keys decrypt identical data in JavaScript encryption?

I’m working on a JavaScript project and wondering if there’s a way to encrypt some data where two different keys can both decrypt the same content. Basically I want to set up encryption where key A can decrypt the data and key B can also decrypt the exact same encrypted data independently.

Is this kind of dual-key decryption possible with JavaScript crypto libraries? I’ve been looking into different encryption methods but haven’t found a clear solution yet. Maybe there’s a specific library or technique that supports this kind of setup?

Any suggestions on how to implement this would be really helpful. I’m open to using any available JavaScript encryption libraries that might support this functionality.

for sure! you can encrypt the data with a random key and then encrypt that random key separately with both key A and key B. this way, either key can be used to access the actual data. it’s a smart method that keeps things secure.

Another approach is using secret sharing schemes like Shamir’s Secret Sharing, which you can implement with libraries like secrets.js-grempe. This method mathematically splits your encryption key into multiple shares, where any subset of shares can reconstruct the original key. You could generate two shares that each independently decrypt your data, or configure it so both keys are required depending on your security requirements. The advantage here is that it’s cryptographically sound and doesn’t require multiple encryption layers like the envelope method mentioned above.

There’s also the option of using threshold cryptography with elliptic curve cryptography, which WebCrypto API supports to some extent. You can generate key pairs where the private keys are mathematically related but still independent. Libraries like noble-secp256k1 or elliptic.js give you more control over the key generation process. The trick is creating keys that share certain mathematical properties while remaining cryptographically secure. I’ve used this approach in a project where we needed multiple department heads to have independent access to encrypted reports. It requires more setup than the envelope method but gives you true dual-key capability without the overhead of double encryption.