Closed Ayushk93 closed 2 years ago
Hi @Ayushk93
Sorry for the delay in getting back to you - somehow my notifications from github are landing up in Spam.
Anyways, what you want to do here is to pass the saltGenerator
function. If you do not pass anything the default function is: const defaultSaltGenerator = (secret) => crypto.randomBytes(16);
, so it is possible that you created your own function here.
We would need to look at more code to debug further,
Maybe i can contribute - this happened to me too because i tried to use "encryptFieldsSync" - and then find did not work, from some other issues i saw here i concluded what is wrong:
In readme.MD there is no example on how to use salt when generating schema, but that point is very important, because if you leave it out (like i did) - find will later use some different encryption - and the problems will occur - so all that is missing in order for all of this to work is to explicitly add salt, like so:
saltGenerator: (secret) => secret.slice(0, 16)
And then the searches will work.
Hope it helps someone!
This is a good point and I will update the README regarding this!
Updated Readme, going to close this issue now!
Below is the code I'm trying for searching purpose but getting
const fieldEncryption = require('mongoose-field-encryption')
const encrypted = fieldEncryption.encrypt('some text', 'secret');
const decrypted = fieldEncryption.decrypt(encrypted, 'secret');
console.log('encrypted ', encrypted);
console.log('decrypted ', decrypted);
Environment: Node.js v14.17.0 in Windows.
Please help.