wheresvic / mongoose-field-encryption

A simple symmetric encryption plugin for individual fields. Dependency free, only mongoose peer dependency.
MIT License
74 stars 32 forks source link

EVP_DecryptFinal_ex:bad decrypt #39

Closed GiboMac closed 2 years ago

GiboMac commented 4 years ago

On my previous laptop, with openssl 1.0.2g 1 Mar 2016 everything works well.

Now after our company migrate to mac, i've imported a db dump, set the same secret used for encrypt my fields.

Then i try to log in into my app this error display

Error: error:06065064:digital envelope routines:EVP_DecryptFinal_ex:bad decrypt
        at Decipheriv.final (internal/crypto/cipher.js:164:28)
        at decrypt (/.../node_modules/mongoose-field-encryption/lib/mongoose-field-encryption.js:71:56)

Anyone with the same error?

OS: osx catalina 10.15.6 OpenSSL 1.1.1g 21 Apr 2020

wheresvic commented 4 years ago

Hi,

As you have correctly diagnosed it, this is a problem with the OpenSSL version, also see: https://stackoverflow.com/questions/34304570/how-to-resolve-the-evp-decryptfinal-ex-bad-decrypt-during-file-decryption

It looks like the only option is to either decrypt the data on the old machine or downgrade the openssl version, decrypt and then upgrade the openssl version and re-encrypt the data.

The other command line options as provided in the stackoverflow answer will not work as this is an internal node.js api crypto that we are using.