Closed mshahulpm closed 1 year ago
I couldn't figure out what was the issue but after deleting collection it seems working fine also in another database there wasn't any problem, it was working fine with old data
ok nice to hear!
I started getting the same error today for an Express project. Deleting the encrypted field from the document and adding it again did the trick, but I cannot figure out the underlying cause.
The argument 'encoding' is invalid for data of length 261. Received 'hex' TypeError [ERR_INVALID_ARG_VALUE]: The argument 'encoding' is invalid for data of length 261. Received 'hex'
at validateEncoding (node:internal/validators:405:11)
at Decipher.update (node:internal/crypto/cipher:175:5)
at decryptAes256Ctr (<path>/node_modules/mongoose-field-encryption/lib/mongoose-field-encryption.js:18:22)
at decrypt (<path>/node_modules/mongoose-field-encryption/lib/mongoose-field-encryption.js:64:14)
at decryptFields (<path>/node_modules/mongoose-field-encryption/lib/mongoose-field-encryption.js:187:26)
at model.<anonymous> (<path>/node_modules/mongoose-field-encryption/lib/mongoose-field-encryption.js:254:7)
at Kareem.execPostSync (<path>/node_modules/kareem/index.js:311:29)
at model.syncWrapper [as $__init] (<path>/node_modules/kareem/index.js:333:26)
at Document.init (<path>/node_modules/mongoose/lib/document.js:638:8)
at Document.$init (<path>/node_modules/mongoose/lib/document.js:654:42)
"mongoose": "^8.0.3",
"mongoose-field-encryption": "^7.0.1",
"node": "20.10.0"
NB: this issue only existing collection with old data
(node:24324) [DEP0106] DeprecationWarning: crypto.createDecipher is deprecated. (Use
node --trace-deprecation ...
to show where the warning was created)TypeError: The argument 'encoding' is invalid for data of length 9. Received 'hex' at new NodeError (node:internal/errors:393:5) at validateEncoding (node:internal/validators:353:11) at Decipher.update (node:internal/crypto/cipher:174:5) at decryptAes256Ctr (C:\Users\mshah\OneDrive\desktop\office-work\idms\residents\node_modules\mongoose-field-encryption\lib\mongoose-field-encryption.js:19:22)
"mongoose": "^6.6.1" "@nestjs/mongoose": "^9.2.0", "mongoose-field-encryption": "^6.0.0",