ciphersweet-js
ciphersweet-js copied to clipboard
Using in the browser
I'm thinking of using this in the browser, as I've read in the documentation that it should be supported.
Basically I need to store some sensitive user data, but don't want the hassle of having to deal with the security side of it. It would be better just not having access or storing the unencrypted data at all in our backend/databases.
So I'm thinking of letting the user enter a key into the web app, then use client side javascript to deal with decryption of data. The key would be stored probably in localStorage, and on every new browser they connect from, they'd need to re-enter the key in order to be able to decrypt or update the sensitive data.
Does this sound feasible to implement using ciphersweet?
It's feasible, but you're probably better off using the AWS JavaScript Encryption SDK.
At the very least, you're going to want to use KMS to manage your keys.
The purpose behind using ciphersweet for this was for searchable encryption. I'm not sure AWS encryption can help with that.
The purpose behind CipherSweet is also symmetric-key encryption, and you'd be giving out your encryption key via JavaScript to anyone who accessed the page.
You can use CipherSweet only for the indexing purposes, and then use something else (e.g. the AWS Encryption SDK, backed by KMS) for record encryption. Or you could use something like SodiumPlus for crypto_box_seal() on the data encryption, against a static public key.
Thank you for the insight. The purpose is to not have access to the Customer data at all from the service provider side.
From what I understand encrypting via KMS does not ensure that. The owner of the AWS account can still decrypt data. That is what we're trying to avoid.
Regarding giving out the encryption key, yes. I am aware of that. But the Encrypted data would still be secured by regular permissions on the user account, only an authorized account (by checking a JWT, for example) could retrieve the encrypted blob and then decrypt it locally.
So it would be an additional layer over a classic permission/ACL layer.
Does this still sound terribly wrong? :)
Hi @paragonie-security! I have been trying to use this in the browser and failed so far, due to dependencies that couldn't be resolved. I tried a very simple example and got errors regarding the dependency fs and others. I tried mocking them with webpack, I tried using ployfills. Nothing seemed to work.
Does this actually work in the browser? And if so, is there and example implemantion somewhere you could point me to?
Any help would be really appreciated!
Best, Tobias
Example Code
import {
BlindIndex,
CipherSweet,
EncryptedField,
FIPSCrypto,
StringProvider,
} from "ciphersweet-js";
export async function foo() {
const cipherSweet = new CipherSweet(
new StringProvider(
"4e1c44f87b4cdf21808762970b356891db180a9dd9850e7baf2a79ff3ab8a2fc"
),
new FIPSCrypto()
);
let ssn = new EncryptedField(cipherSweet, "contacts", "rezeptTyp")
// Add a blind index for the "last 4 of SSN":
.addBlindIndex(
new BlindIndex(
// Name (used in key splitting):
"rezeptTyp",
// List of Transforms:
[],
// Bloom filter size (bits)
16
)
);
// Some example parameters:
let contactInfo = {
name: "John Smith",
ssn: "123-45-6789",
email: "[email protected]",
};
const result = await ssn.prepareForStorage(contactInfo["ssn"]);
return result;
}
Error Messages

I'm interested in a browser-based install, as well. I think most of the reqs are available in browser, such as browserFS and buffer but ofc these need to be thoughtfully included for security concerns.
@paragonie-security coming here with similar concern. Does what @andreialecu says seem terrible?
Btw, @andreialecu I wonder, did you end up with the way you suggested?