Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

findOneandUpdate #88

Open
Bengeljo opened this issue Mar 1, 2023 · 2 comments
Open

findOneandUpdate #88

Bengeljo opened this issue Mar 1, 2023 · 2 comments

Comments

@Bengeljo
Copy link

Bengeljo commented Mar 1, 2023

Hey, I will get straight to the point.
I am not the most expierenced coder and I ran into a problem. I need to update my database during special events.
Multiple data strings are encrypted.
When I call them they get decrytped and displayed correctly and they stay encrypted in the database.
Now when I update them and add something to a string, it kinda lays plain on the database.

I already tried to manuelly set the _enc to false but then when I upload the updated data to the database it stays decrypted and the _enc stays falls even tho it should be uploaded with _enc : true but the program doesn't encrypted it for some reason.

Also doing $set I get an error saying "try it with $setField or something.
I now put it in the add section of the Update and it works so far yet it stays _enc:false

@Bengeljo
Copy link
Author

Bengeljo commented Mar 1, 2023

If I don't put _enc to false I get this
TypeError [ERR_INVALID_ARG_TYPE]: The "iv" argument must be of type string or an instance of ArrayBuffer, Buffer, TypedArray, or DataView. Received undefined at Decipheriv.createCipherWithIV (node:internal/crypto/cipher:134:29) at new Decipheriv (node:internal/crypto/cipher:289:3) at Object.createDecipheriv (node:crypto:149:10) at decryptAes256Ctr (F:\Banlogger\node_modules\mongoose-field-encryption\lib\mongoose-field-encryption.js:18:27) at decrypt (F:\Banlogger\node_modules\mongoose-field-encryption\lib\mongoose-field-encryption.js:64:12) at decryptFields (F:\Banlogger\node_modules\mongoose-field-encryption\lib\mongoose-field-encryption.js:167:26) at model.<anonymous> (F:\Banlogger\node_modules\mongoose-field-encryption\lib\mongoose-field-encryption.js:234:7) at Kareem.execPostSync (F:\Banlogger\node_modules\kareem\index.js:311:29) at model.syncWrapper [as $__init] (F:\Banlogger\node_modules\kareem\index.js:333:26) at Document.init (F:\Banlogger\node_modules\mongoose\lib\document.js:640:8) { code: 'ERR_INVALID_ARG_TYPE' }
And if I put it to _enc: false then it won't encrypt as it stats in the database that _enc is false, so the program kinda skips the encryption.
The error only happens when I add another data string to the already existing one.

@wheresvic
Copy link
Owner

Hi @Bengeljo

It is hard to find out what the issue is without looking at your code. Note that this library comes with a lot of tests which might help you in using it correctly, see this test for findOneAndUpdate:

it("should encrypt string fields on fineOneAndUpdate", function () {

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants